[Haskell-cafe] semantics of type synonym

Tom Davie tom.davie at gmail.com
Tue Dec 29 09:59:36 EST 2009


On Tue, Dec 29, 2009 at 2:47 PM, pbrowne <Patrick.Browne at comp.dit.ie> wrote:

> Hi,
> I am studying the underlying semantics behind Haskell and to what degree
> those semantics are actually implemented. I need to clarify what a *type
> synonym* actual means in relation to Haskell's logic (or formal
> semantics). I used the following type synonym:
>
> type Name = String
> getName(n) = n
>
> I checked the types with two tests:
> -- test 1
> :t "ww"
> "ww" :: [Char]
>
> -- test 2
> :t getName("ww")
> getName("ww") :: Name
>
> Obviously I get two different types.
> In the case of the function Haskells type system seems to pick up enough
> information to determine that “ww” is a Name.
> But I am not sure what is happening with the literal "ww" in the first
> test.
>

This isn't really Haskell doing anything, but a particular implementation...
In Haskell a type synonym is *exactly* that – Name is indistinguishable from
String, which in turn is indistinguishable from [Char].  The
compiler/interpretter is free to return any one of them as it choses.

What's happening here is that ghci(?) is returning the one it thinks is most
likely to be familiar to you.

Bob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091229/c625b5fb/attachment.html


More information about the Haskell-Cafe mailing list