15 May 15:43
Type checker loops with innocent looking associated type synonym
From: Stefan Holdermans <stefan <at> cs.uu.nl>
Subject: Type checker loops with innocent looking associated type synonym
Newsgroups: gmane.comp.lang.haskell.glasgow.user
Date: 2008-05-15 13:46:57 GMT
Subject: Type checker loops with innocent looking associated type synonym
Newsgroups: gmane.comp.lang.haskell.glasgow.user
Date: 2008-05-15 13:46:57 GMT
I've written this cute(Continue reading)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:
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:
afair, the rule of thumb is: please don't report us errors with type
families in 6.8 - it's unofficial and incomplete here. test against
HEAD if you are really interested
RSS Feed