6.4.20050215 inferred types incorrect

Remi Turk rturk at science.uva.nl
Sun Feb 27 17:48:00 EST 2005


Hi,

6.4 appears to incorrectly infer some types in the attached code
when asking with :info in GHCi.
Both 6.2.1 and 6.4.20050215 "inferrings" (is there a nice english
word for that?) are added and commented out.

Greetings,
Remi

-- 
Nobody can be exactly like me. Even I have trouble doing it.
-------------- next part --------------
{-# OPTIONS -fglasgow-exts -cpp #-}
module Foo where

import Random
import Data.Int
import Maybe

data HTCmd k v  = Ins k v

instance (Random k, Random v) => Random (HTCmd k v) where
    random g        = error "Not Implemented"
    randomR (f,t) g = error "Not Implemented"

-- Wrong 6.4 inferred type (:t)
#if 0
exec :: (Monad m) =>
        (t -> k -> v -> m a) -> t -> (a, HTCmd k v) -> m (Maybe a1)
#endif

-- Correct 6.2 inferred type (:t)
#if 0
exec :: (Monad m) =>
        (t -> k -> v -> m a) -> t -> (t1, HTCmd k v) -> m (Maybe a1)
#endif

exec insert ht (i, cmd)
        = case cmd of Ins k v -> insert ht k v>> return Nothing

-- Wrong 6.4 inferred type (:t)
#if 0
test :: (Monad m, Num a, Random a, RandomGen g, Random (HTCmd k v)) =>
        (t -> k -> v -> m a2)
        -> ([(a, a)] -> m t)
        -> (t -> m a1)
        -> g
        -> m (a1, [a1])
#endif

-- Correct 6.2 inferred type (:t)
#if 0
test :: (Monad m, Num t, Random a, RandomGen g, Random (HTCmd k v)) =>
        (t1 -> k -> v -> m a2)
        -> ([(t, a)] -> m t1) -> (t1 -> m t2) -> g -> m (t2, [a1])
#endif
test insert fromList toList g = do
    ht <- fromList ini
    rs <- mapM (exec insert ht) cmds
    l <- toList ht
    return (l, catMaybes rs)
    where
        ini     = [(1, fst $ random g)]
        cmds    = [(1, fst $ random g)]

data HashTable a b

fromList    :: (Eq key)
            => (key -> Int32) -> [(key, val)]
            -> IO (HashTable key val)
fromList    = undefined

update      :: HashTable key val -> key -> val -> IO Bool
update      = undefined

toList      :: HashTable key val -> IO [(key, val)]
toList      = undefined

testHT      :: RandomGen g => g -> IO ([(Int, Int)], [(Integer, Maybe Int)])
testHT g    = test update (fromList fromIntegral) toList g


More information about the Glasgow-haskell-bugs mailing list