explicit signatures and default for integer literals

Mirko Rahn rahn at ira.uka.de
Fri May 27 09:00:52 EDT 2005

Hi all,

an explicit given signature causes ghc to choose the right types for 
integer literals as in

{-# OPTIONS -fglasgow-exts #-}

import Data.Map

f :: Ord a => [a] -> Map a Int
f xs = fromList $ zip xs [0..]

Here the Literal 0 is threated as (0::Int).

But the setting

{-# OPTIONS -fglasgow-exts #-}

import Data.Map

class New a b where new :: a -> b

instance Ord a => New [(a,b)] (Map a b) where new = fromList

g :: Ord a => [a] -> Map a Int
g xs = new $ zip xs [0..]

causes the error message

    Could not deduce (New [(a, b)] (Map a Int)) from the context (Ord a)
       arising from use of `new' at Why.hs:10:7-9

ghc seems to be unable to threat the Literal 0 as (0::Int) this time but 
I do not understand why :-(

Can anyone explain it?


-- Mirko Rahn -- Tel +49-721 608 7504 --
--- http://liinwww.ira.uka.de/~rahn/ ---

More information about the Glasgow-haskell-users mailing list