Type checker loops with innocent looking associated type synonym

Stefan Holdermans stefan at cs.uu.nl
Thu May 15 09:46:57 EDT 2008


I've written this cute ;-) piece of code involving an associated type  
synonym,

   {-# OPTIONS_GHC -fglasgow-exts #-}

   class ZipWithA a where
     type Elem a :: *
     zipWithA    :: [Elem a] -> a

   instance ZipWithA [a] where
     type Elem [a] = a
     zipWithA xs   = xs

   instance ZipWithA b => ZipWithA ([a] -> b) where
     type Elem ([a] -> b) = a -> Elem b
     zipWithA fs          = zipWithA . zipWith ($) fs

and it behaves as intended:

   *Main> zipWithA [2, 3] :: [Int]
   [2,3]

   *Main> zipWithA [pred, succ] [2, 3] :: [Int]
   [1,4]

   *Main> zipWithA [(+), (-)] [2, 3] [5, 7] :: [Int]
   [7,-4]

However, as soon as the overloading cannot be resolved, the type  
checker loops:

   *Main> zipWithA [head, last] ["more than", "haskell"] :: String
   "ml"

   *Main> zipWithA [head, last] ["more than", "haskell"]
   <<loops>>

Just to be clear, I do not expect GHC to be able to type this last  
example, I would just have thought it would want to tell me in finite  
time that it cannot resolve the overloading here.

Should I report this a bug? Or is it perhaps already been taken care  
of in the head? Or am I just plain unreasonable here? :-)

Cheers,

   Stefan


More information about the Glasgow-haskell-users mailing list