What happened to a synonym like Haskell?

I have two functions for loop control, continue and break :

 type Control a = (a -> a) -> a -> a continue :: Control a continue = id break :: Control a break = const id 

Then I wanted to simplify a synonym for type Control . Therefore, I wrote:

 type Endo a = a -> a type Control a = Endo (Endo a) continue :: Control a continue = id break :: Control a break = const id 

However, when I tried to simplify it even further, I received an error message:

 GHCi, version 7.10.2: http://www.haskell.org/ghc/ :? for help Prelude> type Endo a = a -> a Prelude> type Duplicate wa = w (wa) Prelude> type Control a = Duplicate Endo a <interactive>:4:1: Type synonym 'Endo' should have 1 argument, but has been given none In the type declaration for 'Control' 

I do not understand why I am getting this error. Perhaps you could enlighten me.

+4
source share
2 answers

As Fraser said, this kind of thing usually doesn't work, because the type of partially applied type synonyms makes everything unsolvable .

However, if you insert the extension -XLiberalTypeSynonyms , the GHC will insert synonyms until it can work out the output:

 Prelude> type Endo a = a -> a Prelude> type Duplicate wa = w (wa) Prelude> type Control a = Duplicate Endo a <โ€Œinteractive>:4:1:  Type synonym 'Endo' should have 1 argument, but has been given none  In the type declaration for 'Control' Prelude> :set -XLiberalTypeSynonyms Prelude> type Control a = Duplicate Endo a 
+9
source

Type synonyms should be fully applied all the time. You cannot partially apply them.

If you intend to do this, you will most likely need newtype.

+8
source

All Articles