[Haskell-cafe] Non polymorphic numerals option -- avoiding type classes

David Virebayre dav.vire+haskell at gmail.com
Thu Dec 27 10:03:33 CET 2012


Prelude> :t [[1,2],3]

you have a list with 2 elements:
- [1,2]
- 3
the type of [1,2] is [Integer]
the type of 3 is Integer

But all elements in a list must have the same type.





2012/12/27 Rustom Mody <rustompmody at gmail.com>:
>
>
> On Thu, Dec 27, 2012 at 1:48 AM, Roman Cheplyaka <roma at ro-che.info> wrote:
>>
>> * Rustom Mody <rustompmody at gmail.com> [2012-12-26 20:12:17+0530]
>> > So is there any set of flags to make haskell literals less polymorphic?
>>
>> Yes, there is!
>>
>>   % ghci -XRebindableSyntax
>>   GHCi, version 7.6.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.
>>   > import Prelude hiding (fromInteger)
>>   Prelude> let fromInteger = id
>>   Prelude> :t 3
>>   3 :: Integer
>>
>> Roman
>
>
>
> Thanks Roman -- that helps.
> And yet the ghci error is much more obscure than the gofer error:
>
> --- contents of .ghci ---
> :set -XRebindableSyntax
> let fromInteger = id
> ------ ghci session -----
> $ 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 5
> 5 :: Integer
> 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]
>
>
> ----- The same in gofer -----
> Gofer session for:
> pustd.pre
> ? :t [[1,2],3]
>
>
> ERROR: Type error in list
> *** expression     : [[1,2],3]
>
> *** term           : 3
> *** type           : Int
> *** does not match : [Int]
> --------------
> So the error is occurring at the point of the fromInteger (= id) but the
> message does not indicate that
>
> --
> http://www.the-magus.in
> http://blog.languager.org
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



More information about the Haskell-Cafe mailing list