[Haskell-cafe] Non polymorphic numerals option -- avoiding type classes
Rustom Mody
rustompmody at gmail.com
Wed Dec 26 15:42:17 CET 2012
In haskell, we have
Prelude> :t 4
4 :: Num a => a
Prelude>
This may be nice in its generality but it makes it hard (for me at least)
when teaching a beginners course to teach polymorphic vs monomorphic
types. The above leads to even more 'advanced' results like this:
Prelude> :t [[1],2]
[[1],2] :: (Num [t], Num t) => [[t]]
Prelude> [[1],2]
<interactive>:5:6:
No instance for (Num [t0])
arising from the literal `2'
Possible fix: add an instance declaration for (Num [t0])
In the expression: 2
In the expression: [[1], 2]
In an equation for `it': it = [[1], 2]
By contrast in gofer, numeric literals are monomorphic and no such
peculiarities arise
? :t [[1],2]
ERROR: Type error in list
*** expression : [[1],2]
*** term : 2
*** type : Int
*** does not match : [Int]
[[1],2]
ERROR: Type error in list
*** expression : [[1],2]
*** term : 2
*** type : Int
*** does not match : [Int]
So is there any set of flags to make haskell literals less polymorphic?
ie I want 3 to have type Int and 3.0 to have type Float.
This is of course for beginning students to not see type classes too early
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20121226/5bfc41ca/attachment.htm>
More information about the Haskell-Cafe
mailing list