[Haskell-cafe] Understanding type synonym families

Ryan Ingram ryani.spam at gmail.com
Sun Jan 11 18:28:50 EST 2009

>From your blog post:
> Another solution is to use type synonyms to flip the parameter order
> around and write
> > type StateT' m s a = StateT s m a
> That in combination with the TypeSynonymInstances extension would
> allow us to write instance MonadState (StateT' m),

This isn't true, actually; (StateT' m) isn't a valid instance even
with TypeSynonymInstances; type synonyms must be fully applied.

TypeSynonymInstances just lets you do things like

> type List' x = (Int, [x])
> instance Monoid (List' x) where
>     mempty = (0, mempty)
>     mappend (a,b) (c,d) = (a + c, b ++ d)

This is the same as if you wrote the "instance" line as

> instance Monoid (Int, [x])

the compiler is just allowing you to put a fully applied type synonym
in the instance and applying it for you before creating the instance.

  -- ryan

On Sun, Jan 11, 2009 at 1:40 PM, Martijn van Steenbergen
<martijn at van.steenbergen.nl> wrote:
> Hello everybody,
> I think I'm finally beginning to understand how type synonym families [1]
> work, in the way that works best for me: running into a problem to which
> type synonyms offer a solution.
> I wrote down my train of thoughts [2] and I was hoping you could give me
> some feedback: are there any mistakes in my conclusions? Did I miss any
> obvious corollaries? Are the points I make valid?
> Also, I'm hoping it will be valuable to read for those wanting to understand
> type synonym families.
> Thank you in advance,
> Martijn.
> [1]
> http://www.haskell.org/haskellwiki/GHC/Type_families#Detailed_definition_of_type_synonym_families
> [2] http://martijn.van.steenbergen.nl/journal/type-synonym-families/
> _______________________________________________
> 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