data vs type

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

data vs type

Daniel Carrera-2
Hello all,

I'm trying to figure out how 'data' and 'type'. I haven't read any
documentation because I can't find any. Could someone point me to a
document explaining these? I'm happy to RTFM, I just need to know where
the FM is :)

Cheers,
Daniel.
--
      /\/`) http://oooauthors.org
     /\/_/  http://opendocumentfellowship.org
    /\/_/
    \/_/    I am not over-weight, I am under-tall.
    /
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: data vs type

Ketil Malde-2
Daniel Carrera <[hidden email]> writes:

> I'm trying to figure out how 'data' and 'type'.

How data and type...what? :-)

Generally, 'type' introduces type synonyms, i.e. just gives a new name
to an existing type, while 'data' defines new (algebraic) types.

So you can use

   type Name = String

in order to make your program (and, if you're lucky, the compiler
error messages) more legible, or you can use

   data Name = Nick String
             | Initials Char (Maybe Char) Char
             | Full String String

to deal with names in various forms (pronounce the '|' as 'or')

Note that the initial words on the right side in the data declaration
(i.e. "Nick","Initials", and "Full") are type constructors, not types
(like "Name" and "String" are).

Did that help?

(There's also 'newtype', btw, which lets you add a constructor to a
type synonym.)

-k
--
If I haven't seen further, it is by standing in the footprints of giants

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: data vs type

Christian Maeder
In reply to this post by Daniel Carrera-2
Daniel Carrera wrote:
> Hello all,
>
> I'm trying to figure out how 'data' and 'type'. I haven't read any
> documentation because I can't find any. Could someone point me to a
> document explaining these? I'm happy to RTFM, I just need to know where
> the FM is :)

http://www.isi.edu/~hdaume/htut/tutorial.pdf

4.5 Data Types 47

8 Advanced Types 103
8.1 Type Synonyms
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: data vs type

Daniel Carrera-2
In reply to this post by Ketil Malde-2
Ketil Malde wrote:
>>I'm trying to figure out how 'data' and 'type'.
>
> How data and type...what? :-)

oops... "work" :)

> Generally, 'type' introduces type synonyms, i.e. just gives a new name
> to an existing type, while 'data' defines new (algebraic) types.
>
> So you can use
>
>    type Name = String

Ah. Thanks.

> Did that help?

Yes, a lot. :)

Cheers,
Daniel.
--
      /\/`) http://oooauthors.org
     /\/_/  http://opendocumentfellowship.org
    /\/_/
    \/_/    I am not over-weight, I am under-tall.
    /
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: data vs type

Daniel Carrera-2
In reply to this post by Christian Maeder
Christian Maeder wrote:
> http://www.isi.edu/~hdaume/htut/tutorial.pdf
>
> 4.5 Data Types 47
>
> 8 Advanced Types 103
> 8.1 Type Synonyms

Thanks!

Daniel.
--
      /\/`) http://oooauthors.org
     /\/_/  http://opendocumentfellowship.org
    /\/_/
    \/_/    I am not over-weight, I am under-tall.
    /
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe