Re: [Haskell-cafe] Fwd: [Haskell-beginners] Monad instances and type synonyms

On Sun, Apr 14, 2013 at 5:10 PM, Christopher Howard
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. Chris
-------- If I try this, I get
code: -------- Type synonym `Adjustment' should have 1 argument, but has been given none In the instance declaration for `Monad Adjustment' --------
But if I give an argument, then it doesn't compile either (it becomes a "*" kind). And I didn't want to make the type with a regular "data" declaration either, because then I have to give it a constructor, which doesn't fit with what I want the type to do.
-- frigidcode.com
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Chris Wong, fixpoint conjurer e: lambda.fairy@gmail.com w: http://lfairy.github.io/

On Sun, Apr 14, 2013 at 9:28 AM, Chris Wong
On Sun, Apr 14, 2013 at 5:10 PM, Christopher Howard
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.
participants (2)
-
Chris Wong
-
Erik Hesselink