ghci

ghci not loading function from file

你离开我真会死。 提交于 2019-12-03 14:23:08
问题 In test.hs, I have: doubleMe x = x + x In ghci, I type: Prelude> :l test [1 of 1] Compiling Main ( test.hs, interpreted ) Ok, modules loaded: Main. *Main> doubleMe 9 <interactive>:1:0: Not in scope: `doubleMe' *Main> Why? How to fix? 回答1: Are you sure that you're loading the right test.hs? Maybe you're in the wrong directory. Or maybe you didn't save test.hs after adding the definition of doubleMe. 回答2: My guess is that you have defined a main function in your source file. If you have defined

Defining function signature in GHCi

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 11:57:39
Defining a function signature in Haskell's interpreter GHCi doesn't work. Copying an example from this page : Prelude> square :: Int -> Int <interactive>:60:1: error: • No instance for (Show (Int -> Int)) arising from a use of ‘print’ (maybe you haven't applied a function to enough arguments?) • In a stmt of an interactive GHCi command: print it Prelude> square x = x * x How can I declare a function signature and then give function definition in Haskell interactively? also: why can't I simply evaluate the function and see its type (e.g. Prelude> square ) once it has been defined? You can

How can I import a Haskell module in GHCi?

做~自己de王妃 提交于 2019-12-03 10:08:37
I am trying to teach myself Haskell from the book Learn You A Haskell for Great Good. I got up to the last section of chapter 7 (Modules), where it tells how to create your own module. I did a copy and paste of the Geometry module given in the book at the beginning of the section. The name of the file is Geometry.hs, as the book suggested, and the file is in the bin directory for ghci, which is where I previously was able to successfully do a load using :l for another .hs file. When I type the following command in GHCi import Geometry I get the following error: Could not find module 'Geometry'

Haskell: Deriving Show for custom type

对着背影说爱祢 提交于 2019-12-03 09:28:42
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 standalone 'deriving instance' declaration, so you can specify the instance context yourself When

Any way to print out a type of a variable in a do / while / let block?

早过忘川 提交于 2019-12-03 07:14:11
问题 Is there any way to print out the inferred type of a nested variable in ghci ? Consider the code, let f = g where g (x :: Int) = x then, it'd be nice to query the type of g , e.g. :t f.g would print out Int -> Int . 回答1: You can coax this information out by giving an appropriately wrong type annotation and checking the error message. *Main> let f = g where g::a; g (x::Int) = x <interactive>:1:23: Couldn't match type `a1' with `Int -> Int' `a1' is a rigid type variable bound by... 回答2: ghci

Installing Haskell packages on Mac

对着背影说爱祢 提交于 2019-12-03 05:36:38
问题 I can't seem to get a few Haskell packages to install on my Mac (10.6.8). I first tried Happstack and it failed and then I tried Snap. Sometimes when I run ghci I get a segmentation fault. Other times it works and goes like this: GHCi, version 7.4.2: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Prelude> When trying to get Snap: .... .... .... Loading package

Understanding the different behavior of thunks when GHCi let bindings are involved

我的梦境 提交于 2019-12-03 05:26:11
问题 I've been playing with some examples from Simon Marlow's book about parallel and concurrent programming in Haskell and stumbled across an interesting behavior that I don't really understand. This is really about me trying to understand some of the inner workings of GHC. Let's say I do the following in the REPL: λ» let x = 1 + 2 :: Int λ» let z = (x,x) λ» :sprint x x = _ λ» :sprint z z = (_,_) λ» seq x () () λ» :sprint z z = (3,3) Ok, this is pretty much what I expected except that z gets

How to set a program's command line arguments for GHCi?

大憨熊 提交于 2019-12-03 04:10:15
问题 Suppose some Haskell file is executed with runghc Queens.hs gecode_compile Now, this fails, and I want to debug it with ghci . How do I pass the option gecode_compile into the program, so getArgs will read it correctly? Thanks!! 回答1: You can also set the command line arguments in ghci ghci> :set args foo bar ghci> main or ghci> :main foo bar 回答2: You can use the System.Environment.withArgs function to execute main with your desired arguments. Here's an example session (irrelevant details

ghci not loading function from file

蹲街弑〆低调 提交于 2019-12-03 03:29:59
In test.hs, I have: doubleMe x = x + x In ghci, I type: Prelude> :l test [1 of 1] Compiling Main ( test.hs, interpreted ) Ok, modules loaded: Main. *Main> doubleMe 9 <interactive>:1:0: Not in scope: `doubleMe' *Main> Why? How to fix? Are you sure that you're loading the right test.hs? Maybe you're in the wrong directory. Or maybe you didn't save test.hs after adding the definition of doubleMe. My guess is that you have defined a main function in your source file. If you have defined a main function, loading the module with :l test won't import any functions but main . In that case you can load

Haskell Graphics Library that works in GHCi on MacOS X

青春壹個敷衍的年華 提交于 2019-12-03 02:44:43
问题 Does there exist a Haskell graphics library or binding to an external library that fulfills the following requirements: Can be used from ghci , i.e. I don't have to link and restart the program. Works on MacOS X. (Tricky in conjunction with 1!) Can do simple vector graphics (lines, polygons, simple fills and strokes). Can put bitmap images on screen. Example: blit a 17x12 .bmp image. ? Please include a minimal source code example or a reference to it (just a window on screen, maybe with a