[Haskell-cafe] Re: Monad instance for partially applied type constructor?

Ryan Ingram ryani.spam at gmail.com
Wed Sep 29 17:41:42 EDT 2010

It's hard.  Here's a simple example:

type Foo f = f Int

class C (f :: (* -> *) -> *) where
   thingy :: f [] -> f IO

-- Should this ever typecheck?  I would say no; there's no way to
unify f [] with [Int].
callThingy :: [Int] -> IO Int
callThingy = thingy

-- but what if you say this?
instance C Foo where
     -- thingy :: Foo [] -> Foo IO
     -- therefore,
     -- thingy :: [Int] -> IO Int
     thingy (x:_) = return x

Basically, allowing instances for type functions requires you to
*un-apply* any type functions to attempt to do instance selection.

  -- ryan

On Wed, Sep 29, 2010 at 2:15 PM, DavidA <polyomino at f2s.com> wrote:
> Ryan Ingram <ryani.spam <at> gmail.com> writes:
>> Haskell doesn't have true type functions; what you are really saying is
>> instance Monad (\v -> Vect k (Monomial v))
> Yes, that is exactly what I am trying to say. And since I'm not allowed to say
> it like that, I was trying to say it using a type synonym parameterised over v
> instead. It appears that GHC won't let you use partially applied type synonyms
> as type constructors for instance declarations. Is this simply because the GHC
> developers didn't think anyone would want to, or is there some theoretical
> reason why it's hard, or a bad idea?
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list