[Haskell-cafe] Fwd: [Haskell-beginners] Monad instances and type synonyms
Erik Hesselink
hesselink at gmail.com
Sun Apr 14 11:03:38 CEST 2013
On Sun, Apr 14, 2013 at 9:28 AM, Chris Wong
<chrisyco+haskell-cafe at gmail.com> wrote:
> On Sun, Apr 14, 2013 at 5:10 PM, Christopher Howard
> <christopher.howard at frigidcode.com> wrote:
>> type Adjustment a = SaleVariables -> a
>>
>> [...]
>>
>> instance Monad Adjustment where
>>
>> (>>=) = ...
>> return = ...
>
> Essentially, you can't partially apply type synonyms. I don't recall
> the exact reasoning, but if this sort of thing was allowed it would
> probably poke funny holes in the type system.
>
> Also, Control.Monad.Instances already supplies a Monad instance for
> functions (r -> a). So even if that did pass, you'd bump into
> overlapping instances anyway.
The fact that that instance exists shows that you can define an
instance like this (even though you don't have to, since it already
exists). The trick is to define the type synonym partially applied.
When you do that, you can define the instance:
type Adjustment = (->) SaleVariables
instance Monad Adjustment where
Note that this needs the extensions TypeSynonymInstances and FlexibleInstances.
Erik.
More information about the Haskell-Cafe
mailing list