explicit signatures and default for integer literals
Dinko Tenev
dinko.tenev at gmail.com
Fri May 27 11:22:51 EDT 2005
*Main> :type fromList
fromList :: (Ord k) => [(k, a)] -> Map k a
*Main> :type new
new :: (New a b) => a -> b
The type of new probably accounts for the difference (even though it
still makes me wonder what the big deal is :)
Using functional dependencies seems to fix it, i.e.:
class New a b | a -> b where new :: a -> b
or, perhaps more appropriately:
class New a b | b -> a where new :: a -> b
Cheers,
D. Tenev
On 5/27/05, Mirko Rahn <rahn at ira.uka.de> wrote:
>
> 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?
>
> Thanks,
>
> --
> -- Mirko Rahn -- Tel +49-721 608 7504 --
> --- http://liinwww.ira.uka.de/~rahn/ ---
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users at haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
>
More information about the Glasgow-haskell-users
mailing list