[Haskell-beginners] Re: how to define records containing finite length lists.

Christian Maeder Christian.Maeder at dfki.de
Wed Dec 2 13:43:36 EST 2009


Srikanth K schrieb:
> Hi,
>    I want to define a record say "Student".  The 'C' equvivalent for the
> same could be
>  
> struct Person {
>      char name[10]
>      int age }
>  
> The closest I can find for doing such a thing in haskell appears to be
>  
> data Person = Person{
>      name :: [char]
>      age :: Int
> }

you would use:

  data Person = Person
    { name :: String
    , age :: Int }

Note the "," and the capital first letter for types.

> I have not yet been able to find a suitable way to specify the
> constraint on the length of list(name in this case).
> So can someone let me know how we can impose this length constratint on
> the list  and derive a new type.
>  
> If standard haskell doesn't give this flexibility, are there any
> extensions in ghc to achieve the same. 

The flexibility lies in not fixing the maximal size!

HTH Christian


More information about the Beginners mailing list