ghci

Can not load a file that uses standard libraries in haskell

隐身守侯 提交于 2020-12-26 08:10:11
问题 Hi I use GHCI and can normally load my files. Now I need to load a file that uses random. I get this error. Chatterbot.hs:3:1: error: Could not find module ‘System.Random’ Use -v to see a list of the files searched for. | 3 | import System.Random | ^^^^^^^^^^^^^^^^^^^^ This is very weird since it works for my friend who also have just installed GHCI and did nothing other than me. The main difference is that I am on windows. I really don t understand this and have tried googling a bit and many

How can I compare and return data using a list of data

会有一股神秘感。 提交于 2020-05-15 07:48:23
问题 I'm a newbie to Haskell and I'm struggling to find a way to use class member variables to return the member variable I am looking for. I have this data: data Place = Place {name :: String, north :: Float, east :: Float, rainfall :: [Int] } deriving (Eq, Ord, Show) testData :: [Place] testData = [ Place "London" 51.5 (-0.1) [0, 0, 5, 8, 8, 0, 0], Place "Norwich" 52.6 (1.3) [0, 6, 5, 0, 0, 0, 3], Place "Birmingham" 52.5 (-1.9) [0, 2, 10, 7, 8, 2, 2], Place "Hull" 53.8 (-0.3) [0, 6, 5, 0, 0, 0,

ghci special case for Applicative?

瘦欲@ 提交于 2020-04-12 09:57:54
问题 In ghci: λ> :t (pure 1) (pure 1) :: (Applicative f, Num a) => f a λ> show (pure 1) <interactive>:1:1: No instance for (Show (f0 a0)) arising from a use of `show' Possible fix: add an instance declaration for (Show (f0 a0)) In the expression: show (pure 1) In an equation for `it': it = show (pure 1) λ> pure 1 1 Does this mean that ghci execute Applicative and displays the result, just like IO ? Note that pure () and pure (+1) don't print anything. 回答1: You get the same behaviour if you use

Cannot enter multiline statements in GHCi [duplicate]

倾然丶 夕夏残阳落幕 提交于 2020-02-27 23:13:49
问题 This question already has answers here : Multi-line commands in GHCi (4 answers) Closed 6 years ago . let x=1 y=2 z=3 does not work in GHCi, forcing me to use let {x=1;y=2;y=3} instead. How can I fix this problem? 回答1: The documentation says: GHCi also has a multiline mode, enabled by :set +m, in which GHCi detects automatically when the current statement is unfinished and allows further lines to be added. A multi-line input is terminated with an empty line. The multiline mode makes GHCi

Cannot enter multiline statements in GHCi [duplicate]

纵然是瞬间 提交于 2020-02-27 23:13:46
问题 This question already has answers here : Multi-line commands in GHCi (4 answers) Closed 6 years ago . let x=1 y=2 z=3 does not work in GHCi, forcing me to use let {x=1;y=2;y=3} instead. How can I fix this problem? 回答1: The documentation says: GHCi also has a multiline mode, enabled by :set +m, in which GHCi detects automatically when the current statement is unfinished and allows further lines to be added. A multi-line input is terminated with an empty line. The multiline mode makes GHCi

Weird behavior of (^) in Haskell

拟墨画扇 提交于 2020-02-03 04:11:31
问题 Why does GHCi give incorrect answer below? GHCi λ> ((-20.24373193905347)^12)^2 - ((-20.24373193905347)^24) 4.503599627370496e15 Python3 >>> ((-20.24373193905347)**12)**2 - ((-20.24373193905347)**24) 0.0 UPDATE I would implement Haskell's (^) function as follows. powerXY :: Double -> Int -> Double powerXY x 0 = 1 powerXY x y | y < 0 = powerXY (1/x) (-y) | otherwise = let z = powerXY x (y `div` 2) in if odd y then z*z*x else z*z main = do let x = -20.24373193905347 print $ powerXY (powerXY x 12

“No instance for” error

眉间皱痕 提交于 2020-01-23 06:44:19
问题 Following an example in http://en.wikibooks.org/wiki/Haskell/Beginning Prelude> let abs x = if x < 0 then -x else x Prelude> abs 5 5 Prelude> abs -3 <interactive>:1:6: No instance for (Num (a0 -> a0)) arising from the literal `3' Possible fix: add an instance declaration for (Num (a0 -> a0)) In the second argument of `(-)', namely `3' In the expression: abs - 3 In an equation for `it': it = abs - 3 What's wrong? 回答1: Haskell thinks you're trying to subtract 3 from abs , and is complaining

Iteratively printing every integer in a List

末鹿安然 提交于 2020-01-15 04:29:05
问题 Say I have a List of integers l = [1,2] Which I want to print to stdout . Doing print l produces [1,2] Say I want to print the list without the braces map print l produces No instance for (Show (IO ())) arising from a use of `print' Possible fix: add an instance declaration for (Show (IO ())) In a stmt of an interactive GHCi command: print it `:t print print :: Show a => a -> IO () So while I thought this would work I went ahead and tried: map putStr $ map show l Since I suspected a type

Iteratively printing every integer in a List

人走茶凉 提交于 2020-01-15 04:28:07
问题 Say I have a List of integers l = [1,2] Which I want to print to stdout . Doing print l produces [1,2] Say I want to print the list without the braces map print l produces No instance for (Show (IO ())) arising from a use of `print' Possible fix: add an instance declaration for (Show (IO ())) In a stmt of an interactive GHCi command: print it `:t print print :: Show a => a -> IO () So while I thought this would work I went ahead and tried: map putStr $ map show l Since I suspected a type

Defining function signature in GHCi

☆樱花仙子☆ 提交于 2020-01-12 07:09:16
问题 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