Friday, 29 April 2016

Haskell: Prelude module


Haskell imports Prelude module by default. Prelude module defines most basic functions. You can use the functions defined in Prelude module, without importing them.

$ ghci
GHCi, version 7.10.3: http://www.haskell.org/ghc/  :? for help
Prelude> 
Prelude> head "abcd"
'a'
Prelude> length "abcd"
4
Prelude> reverse "abcd"
"dcba"

functions like head, length, reverse are available in Prelude module.

How to disable this automatic import?
Use the command ‘ghci –XnoImplicitPrelude’ to disable automatic Prelude import.

$ ghci -XNoImplicitPrelude
GHCi, version 7.10.3: http://www.haskell.org/ghc/  :? for help
> 
> head "abcd"

<interactive>:3:1: Not in scope: head
> 
> length "abcd"

<interactive>:5:1: Not in scope: length
> 


Since you disabled automatic Prelude import, you are getting above errors while calling head, length functions.





Previous                                                 Next                                                 Home

No comments:

Post a Comment