ghci

How to use 'oneof' in quickCheck (Haskell)

。_饼干妹妹 提交于 2019-12-04 08:40:42
I am trying to write a prop that changes a Sudoku and then checks if it's still valid. However, I am not sure how to use the "oneof"-function properly. Can you give me some hints, please? prop_candidates :: Sudoku -> Bool prop_candidates su = isSudoku newSu && isOkay newSu where newSu = update su aBlank aCandidate aCandidate = oneof [return x | x <- candidates su aBlank] aBlank = oneof [return x | x <- (blanks su)] Here are some more info... type Pos = (Int, Int) update :: Sudoku -> Pos -> Maybe Int -> Sudoku blanks :: Sudoku -> [Pos] candidates :: Sudoku -> Pos -> [Int] [return x | x <-

Function to evaluate haskell in ghci while editing source file using Emacs

a 夏天 提交于 2019-12-04 08:29:32
I'm editing a haskell source file. I want to run my main function in my inferior-haskell buffer (already opened in a different frame) and continue editing my source file. To do this, I do C-c C-l , change frame, main<ret> , change back to original frame This seems quite inefficient. I'd like an emacs function/key that does it one shot. There is actually a function to do this already defined in inf-haskell.el : inferior-haskell-load-and-run . This loads your current file and runs :main . You can bind it to a key in Haskell mode by adding a hook: (defun my-haskell-mode-hook () (local-set-key

ghci self-referencing assignment

夙愿已清 提交于 2019-12-04 01:15:07
问题 I was learning some new Haskell today, when I tried something in ghci. It basically boiled down to this: Prelude> let x = 6 Prelude> x 6 Prelude> let y = show x Prelude> y "6" Prelude> let x = show x Prelude> x "\"\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\" --(repeats) So can ghci not self-reference in assignment? I feel like it's akin to i = i++; in C, or trying to reference previous assignments of a let (not let* ) in Scheme. Is there anyway

How to set ghci options for cabal repl?

我是研究僧i 提交于 2019-12-03 23:43:40
I have a haskell project which I compile with -Werror by default. This means that when I run cabal repl it runs with the option -Werror turned on. This means that for example when I evaluate 2 + 2 I get the following error message: <interactive>:2:3: Warning: Defaulting the following constraint(s) to type `Integer' (Num a0) arising from a use of `+' In the expression: 2 + 2 In an equation for `it': it = 2 + 2 So I need a way to turn on the option, -w or maybe -Wwarn on by default for cabal repl . How do I do this? Also what are the default flags for ghci ? You can set GHCi options in your ~/

Haskell: non-exhaustive-patterns

╄→гoц情女王★ 提交于 2019-12-03 17:39:13
问题 I am training for a test tomorrow to complete my introduction to functional programming but there is one thing I don't understand. Whenever I have a program like: test [] = [] test (x:xs) = test (xs) What he does is that he takes the first element out of the list and continues with the rest. Whenever there is just one left, xs should be [] which in turn should trigger test [] = [] . But whenever I run this algorithm I get an error. Exception: <interactive>:20:5-16: Non-exhaustive patterns in

Haskell type operator precedence

◇◆丶佛笑我妖孽 提交于 2019-12-03 16:36:52
问题 When the language extension TypeOperators is enabled, it's possible to define own type operators. Also, it's possible to set their relative precedence with infix* . But what's the precedence of (->) , for example? > :i (->) data (->) a b -- Defined in `GHC.Prim' instance Monad ((->) r) -- Defined in `GHC.Base' instance Functor ((->) r) -- Defined in `GHC.Base' instance Applicative ((->) a) -- Defined in `Control.Applicative' instance Arrow (->) -- Defined in `Control.Arrow' instance Monoid b

haskell parse error in pattern for n+k pattern

久未见 提交于 2019-12-03 15:33:28
问题 I have started working my way through Erik Meijer's 13-part lectures (and Graham Hutton's slides) to learn Haskell. On the slides for Chapter 4, on page 13, it introduces the pattern-matching syntax for n+k patterns. In particular, it says: As in mathematics, functions on integers can be defined using n+k patterns, where n is an integer variable and k>0 is an integer constant. pred :: Int -> Int pred (n+1) = n When I tried this on my own in the REPL I get an error message: *Main> let mypred

Specifying the search path for “load” operations in ghci

喜你入骨 提交于 2019-12-03 15:04:42
In Loading source files it states that the search path for finding source files is specified with the -i option : ghci -idir1:...:dirn Does this mean that when one performs : :load test.hs then ghci looks in the directories above for test.hs? I saw the response at Problem Specifying Source Directory to GHC but I am still not clear about this. For example in Windows XP I put test.hs in : C:\Documents and Settings\winuser\My Documents and then ran : ghci -iC:\Documents and Settings\winuser\My Documents However upon doing :load test.hs , ghci complained about not being able to find the file.

Saving my running toplevel for later

↘锁芯ラ 提交于 2019-12-03 14:37:31
问题 When working in the ocaml or ghci toplevels I often build up a significant "context" for want of a better word, values bound, functions, modules loaded, and so on. Is there a way to save all of that and reload it later so I can continue exactly where I left off? Or better yet, dump out the entire lot as a text file that could be reloaded or be trivially modified into code that I could compile into an executable (e.g. by adding a Main)? 回答1: Users of HOL light have had similar needs, and they

Haskell: Deriving Show for custom type

那年仲夏 提交于 2019-12-03 14:33:39
问题 I have this type definition: data Operace = Op (Int->Int->Int) String (Int->Int->Int) deriving Show I want to print this type into the interactive shell (GHCi). All that should be printed is the String field. I tried this: instance Show Operace where show (Op op str inv) = show str But I still keep getting No instance for (Show (Int -> Int -> Int)) arising from the 'deriving' clause of a data type declaration Possible fix: add an instance declaration for (Show (Int -> Int -> Int)) or use a