fundeps for extended Monad definition

Ashley Yakeley ashley@semantic.org
Wed, 05 Mar 2003 01:53:20 -0800


In article 
<DE924A789E3C124F8C8A319F273357E7014E30CF@lon-msg-01.europe.corp.microso
ft.com>,
 "Simon Peyton-Jones" <simonpj@microsoft.com> wrote:

> Here's a less complicated variant of the same problem:
> 
> 	class C a b | a -> b where {}
> 
> 	instance C Int Int where {}
> 
> 	f :: (C Int b) => Int -> b
> 	f x = x
> 
> Is the defn of f legal?  Both GHC and Hugs reject it because the
> inferred type of f is more like
> 	C Int Int => Int -> Int

If this were allowed, it would effectively allow type-lambda. For 
instance, I have a type function T that maps Int to Bool and Bool to 
Char:

  class C a b | a -> b
  instance C Int Bool
  instance C Bool Char

  newtype T a = MkT (forall b.(C a b) => b)
  helperIn :: (forall b.(C a b) => b) -> T a
  helperIn b = MkT b; -- currently won't work
  helperOut :: T a -> (forall b.(C a b) => b)
  helperOut (MkT b) = b;

Here T is a type-constructor that does that. If I like, I can represent 
Char as "T (T Int)", though of course I need to use the helper functions 
to actually use it as a Char.

-- 
Ashley Yakeley, Seattle WA