[Haskell-cafe] Re: Monad instance for partially applied type
constructor?
Ryan Ingram
ryani.spam at gmail.com
Thu Sep 30 19:21:41 EDT 2010
On Wed, Sep 29, 2010 at 9:13 PM, Alexander Solla <ajs at 2piix.com> wrote:
> On 09/29/2010 02:15 PM, DavidA wrote:
>>>
>>> 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.
>
> Why not:
>
> instance Monad ((->) Vect k (Monomial v))
No, what he's trying to say is
> instance Monad (Vect k . Monomial)
with some type-level composition for .
which would give these signatures:
> return :: forall a. a -> Vect k (Monomial a)
> (>>=) :: forall a b. Vect k (Monomial a) -> (a -> Vect k (Monomial b)) -> Vect k (Monomial b)
Notice that the "forall" variables are inside parentheses in the type;
this is what Haskell doesn't allow.
Of course you can
> newtype VectMonomial k a = VM { unVM :: Vect k (Monomial a) }
> instance Monad (VectMonomial k) where ...
But now you need to wrap/unwrap using VM/unVM.
-- ryan
More information about the Haskell-Cafe
mailing list