[Haskell-cafe] difference between type and newtype

Bulat Ziganshin bulat.ziganshin at gmail.com
Sat Aug 26 11:46:29 EDT 2006

Hello Andrea,

Saturday, August 26, 2006, 6:40:06 PM, you wrote:

>> Of course, newtype can also be used to define type whose only field
>> contains some function:
>> newtype F = F (String->Int)
>> Again, in this case language guarantees that internal F representation
>> will be the same as for plain (Int->String) function and therefore the
>> same as for type synonym:
>> type S = String->Int
>> But from programmer POV, the difference still holds: while S denotes
>> function of given type and can be used interchangeably with full
>> notion of this function type, F is just the type which internally
>> contains such function. 

> As I said in a previous message it took me almost two day to grasp
> this distinction. 

'newtype' construction was added exactly to allow definition of new
distinctive types with the same 'contents' as existing ones. as Udo
already stated, this may be required for hiding representation or just
to define specific instance for some specific type that you use in
your program

i highly recommend you to look at "Haskell history" paper,
http://haskell.org/haskellwiki/History_of_Haskell . Wadler was
its coauthor and this paper written in the same clear and concise way
as his papers. Part II of the paper makes an excellent overview of
features that makes Haskell so special, including brief overview of
various monads and story that precedes inclusion of newtype in Haskell 1.3

Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com

More information about the Haskell-Cafe mailing list