ghci

Error haskell: not in scope. What does that mean?

萝らか妹 提交于 2019-12-31 20:18:06
问题 I started with Haskell today and all the functions I perform on ghci display this message. I just want to know why this is happening. I know there are a lot of questions about this, but this is a simple case and I need to understand this error in the beginning function3 :: Int -> [Int] function3 x = [a | a <- [1..x] mod a x == 0] 回答1: Did error happen when you type the function type in GHCi? $ ghci GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help Prelude> function3 :: Int -> [Int]

Which is the type of (flip .)?

我们两清 提交于 2019-12-31 07:37:05
问题 I'm trying to understand why the type of: (flip .) is: (a -> a1 -> b -> c) -> a -> b -> a1 -> c First of all, the type of: flip: is (a -> b -> c) -> b -> a -> c (.): is (b -> c) -> (a -> b) -> a -> c I will rename the variables to be more clear in my explanation, so the types: flip: is (ax -> bx -> cx) -> bx -> ax -> cx (.): is (by -> cy) -> (ay -> by) -> ay -> cy Then I try substituing like this: ax = (by -> cy) bx = (ay -> by) cx = ay -> cy So the resulting type is: (ay -> by) (by -> cy) ->

Which is the type of (flip .)?

人盡茶涼 提交于 2019-12-31 07:37:03
问题 I'm trying to understand why the type of: (flip .) is: (a -> a1 -> b -> c) -> a -> b -> a1 -> c First of all, the type of: flip: is (a -> b -> c) -> b -> a -> c (.): is (b -> c) -> (a -> b) -> a -> c I will rename the variables to be more clear in my explanation, so the types: flip: is (ax -> bx -> cx) -> bx -> ax -> cx (.): is (by -> cy) -> (ay -> by) -> ay -> cy Then I try substituing like this: ax = (by -> cy) bx = (ay -> by) cx = ay -> cy So the resulting type is: (ay -> by) (by -> cy) ->

Haskell - Export data constructor

泪湿孤枕 提交于 2019-12-30 08:26:11
问题 I have this data on my Module Formula : data Formula = Formula { typeFormula :: String, nbClauses :: Int, nbVars :: Int, clauses :: Clauses } And I want to export it but I don't know the right syntax : module Formula ( Formula ( Formula ), solve ) where Someone can tell me the right syntax please ? 回答1: Some of your confusion is coming from having the same module name as the constructor you're trying to export. module Formula ( Formula ( Formula ), solve ) where Should be module Formula (

Ghc: partially compile Haskell code?

前提是你 提交于 2019-12-30 02:47:10
问题 When I compile a Haskell file with ghci , typically with :load , and if there is no type error, all the expressions are loaded in the ghc interpreter. It's very nice: I can play around with :t to figure out the type of various expressions. My problem is: if there is a tiny error somewhere, ghci is not able to load anything (not even the imported modules!!), which makes finding the right types even more difficult. I always do the same: comment out all the bits that do not typecheck, find the

Manual derivation of the type for `f1 x xs = (filter . (<)) x xs`

旧巷老猫 提交于 2019-12-25 02:19:32
问题 I want to manually derive the type of: f1 x xs = (filter . (<)) x xs First time we see x , so: x :: t1 Then (<) has this type: (<) :: Ord a1 => a1 -> a1 -> Bool We can only say (< x) if the following types can be unified: t1 ~ a1 Then x :: a1 So (<x) :: Ord a1 => a1 -> Bool Filter has this type filter :: (a2 -> Bool) -> [a2] -> [a2] First time to see xs, so: xs :: t2 We can only say (filter . (<)) x xs if the following types can be unified: a1 -> Bool ~ a2 -> Bool t2 ~ [a2] So I get that f1 :

Any way to add patterns, type signature, to a function in GHCi?

℡╲_俬逩灬. 提交于 2019-12-24 17:19:01
问题 ^-- No, it doesn't entirely. My question covers ADDING patterns and type signatures interactively...which is apparently impossible. The most basic things you might try do from early tutorials won't work in GHCi: foo [] = [] foo (x:xs) = x : foo xs That works if you put it into foo.hs and at the GHCi prompt type :load foo.hs . You can then invoke foo on a list and get the list back. Early Google searches tell you that in GHCi you need a let statement. But in this case (a function defined with

Modifying Emacs Inferior Haskell processes to enable CPP processing

ⅰ亾dé卋堺 提交于 2019-12-24 14:23:58
问题 If we look at the source of The random package we have a file Random.hs . Because of CPP extensions one has to invoke ghci via the following command : ghci -cpp Random.hs Alternatively one can do : ghci -cpp and then from within ghci : Prelude GOA> :load Random [1 of 1] Compiling System.Random ( Random.hs, interpreted ) Ok, modules loaded: System.Random. If I use Emacs Inferior Haskell mode (Emacs/Inferior Haskell processes) and I have the source : module Main where import System.Random gen =

Generating all possible combinations of numbers in a triplet?

北城余情 提交于 2019-12-24 04:36:09
问题 Say for example I want to construct a triplet, taking in every combination of numbers from 1..100 in a triplet; i.e: [(0,0,0),(0,0,1),(0,1,1),(1,1,1),(0,0,2),(0,1,2),(0,2,2),(1,2,2)] ..etc etc, up until a given bound (i.e: 100: giving us a final triplet of (100,100,100)); is there any reasonable way of doing this within haskell, or would I be best off writing a method that in short held a boundary pointer, and recursively increased each number until it was equal to the number to its right?

Instance declaration in Haskell

别来无恙 提交于 2019-12-23 20:00:52
问题 I have these two functions: primes = sieve [2..] where sieve (p:xs) = p : sieve [x|x <- xs, x `mod` p > 0] isPrime number = number /= 1 && null [x | x <- takeWhile (\x -> x < (ceiling . sqrt) number) primes, mod number x == 0] The thing is that when I'm trying to load module which contains those functions, I see following error message: [2 of 2] Compiling Main ( euler37.hs, interpreted ) euler37.hs:6:70: No instance for (RealFrac Int) arising from a use of `ceiling' Possible fix: add an