[Haskell-cafe] Non polymorphic numerals option -- avoiding type classes
Rustom Mody
rustompmody at gmail.com
Thu Dec 27 17:48:15 CET 2012
On Thu, Dec 27, 2012 at 8:26 PM, Kim-Ee Yeoh <ky3 at atamo.com> wrote:
> Hi David, it looks like Rustom's aware that haskell's not lisp. What he
> really wants methinks is a way to suppress type classes altogether! That or
> a NoOverloadedNumerals extension.
>
> -- Kim-Ee
>
>
I'm not really sure about that... Look!
ghci with default startup
--------------------
$ ghci
GHCi, version 7.4.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :t [[1,2],3]
[[1,2],3] :: (Num [t], Num t) => [[t]]
So it would appear that ghci is giving a well-typing for [[1,2], 3].
But is it?
Prelude> [[1,2],3]
<interactive>:3:8:
No instance for (Num [t0])
arising from the literal `3'
Possible fix: add an instance declaration for (Num [t0])
In the expression: 3
In the expression: [[1, 2], 3]
In an equation for `it': it = [[1, 2], 3]
-------------------
So is it well-typed in ghci or not??
And now we add Roman's suggestions...
$ cat .ghci
:set -XRebindableSyntax
let fromInteger = id
And run ghci again
$ ghci
GHCi, version 7.4.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :t [[1,2],3]
<interactive>:1:8:
Couldn't match expected type `[Integer]' with actual type `Integer'
Expected type: Integer -> [Integer]
Actual type: Integer -> Integer
In the expression: 3
In the expression: [[1, 2], 3]
Prelude> [[1,2],3]
<interactive>:3:8:
Couldn't match expected type `[Integer]' with actual type `Integer'
Expected type: Integer -> [Integer]
Actual type: Integer -> Integer
In the expression: 3
In the expression: [[1, 2], 3]
Prelude>
So far so good -- when an expression is type-wrong, its 'wrongness' is the
same irrespective of whether I ask for its type or evaluate it.
But now we are in for new surprises: Try out
f x y = x / y
Prelude> :l f
[1 of 1] Compiling Main ( f.hs, interpreted )
f.hs:1:11: Not in scope: `/'
Failed, modules loaded: none.
Prelude> (/)
Oh is it that now integer literals are just plain Integers and cant be
divided using '/' ??
So lets replace '/' with '+'
f.hs:1:11: Not in scope: `+'
And now I am at my wits end!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20121227/b804b26b/attachment.htm>
More information about the Haskell-Cafe
mailing list