This work ok:
increment :: Int -> Int
increment i = i + 1
But why this not:
module MyFile where
import Prelude (Show)
increment :: Int -> Int
increment i = i + 1
Hugs say: Undefined type constructor "Int"
I suppose i need to import more things.
Int is defined in Prelude, but in your case you only import Show from Prelude. Therefore, the definition of Int cannot be found. To rectify, modify as import Prelude (Show, Int, (+)).
In many Haskell programs, you want to leave the Prelude out of your imports and just let it be imported automatically.
In almost all the rest, you want to import most of the Prelude, but leave some pieces out. This can be done using, e.g.,
import Prelude hiding (head, tail, (++))
In some cases, that will be accompanied by an import to get access to the hidden parts:
import qualified Prelude as P
In virtually all remaining cases, you will be using some alternative prelude instead of the standard one. The only times I can imagine writing anything that doesn't import most of some prelude are when actually implementing the base modules for a Haskell system, or writing an alternative prelude.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With