haskell, why does head' function okay in ghci but cannot be compiled? -
head' :: [a] -> head' [] = error "cannot phone call head on emply list." head' (x:_) = x main = putstrln "hello" allow ret = head' [4,5,6] putstrln ret
above code, can load in ghci , phone call head' function correctly. when set file , seek compile it. thows error. cannot figure out why that. need help; thanks.
[1 of 1] compiling main ( head.hs, head.o ) head.hs:7:22: no instance (num string) arising literal `4' possible fix: add together instance declaration (num string) in expression: 4 in first argument of head', namely `[4, 5, 6]' in expression: head' [4, 5, 6]
putstrln
takes string
(its type putstrln :: string -> io ()
), not numeric type. want print
... print ret
print
can take type has show
instance. type print :: show => -> io ()
haskell
No comments:
Post a Comment