I am totally newbie to haskell.
I have such snippet code
lucky:: Int->String
lucky 7 = "LUCKY NUMBER SEVEN!"
lucky x = "Sorry , youre out of luck pal!"
I tried to input to terminal directly, seems not right.
But if I want to put this in file and load this file, then call lucky function. How should I construct this file?
Thank you!
I tried this:
module Main where
lucky:: Int->String
lucky 7 = "LUCKY NUMBER SEVEN!"
lucky x = "Sorry , youre out of luck pal!"
main = do
But when i try to call lucky in terminal, i got this:
factorial.hs:7:8: Empty 'do' construct
lucky 7
<interactive>:1:1: Not in scope: `lucky'
The problem is that your last line,
main = do, is a syntax error; if your file has a syntax error then none of the functions in it will load. It should work fine if you take out your definition of main and try to load it.On an unrelated note, generally Haskell type signatures are written with spacing like
lucky :: Int -> String.