[Haskell-beginners] Data type

Matthew Moppett matthewmoppett at gmail.com
Tue May 5 15:23:53 UTC 2015


Here's a quick example using ghci:

Prelude> let a = Person length
Prelude> :type a
a :: Person
Prelude> (firstName a) "Bob"
3


On Tue, May 5, 2015 at 10:19 PM, Shishir Srivastava <
shishir.srivastava at gmail.com> wrote:

> Hi,
>
> Could anyone please have a look and let me know how you can create the
> instance of this data type ?
>
> ---
>  data Person = Person { firstName ::String -> Int }
> ---
>
> I've seen this type of syntax in a lot of places in haskell code where a
> new data type is defined in terms of functions rather than concrete data
> types.
>
> I am not trying to achieve anything out of this but purely as an exercise
> in understanding the record syntax.
>
> As far as I understand the data type is function based and takes a
> 'function' instead of a value of a concrete type so how does one create an
> instance of this type.
>
> Thanks,
> Shishir
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150505/80755cee/attachment.html>


More information about the Beginners mailing list