[Haskell-cafe] Record initialise question

John Ky newhoggy at gmail.com
Fri Jun 5 05:33:56 EDT 2009


Hi all,

I have some sample code:

>  full = do
>     let myOrder = initOrder
>              { item = Just initItem
>                 { itemId = "Something"
>                 }
>              , operation = Just Buy
>              }
>     putStrLn $ show myOrder
>     return ()

This is just a test project, but in a real project, I would have a more
elaborate structure.

Notice initOrder and initItem.  I actually need to know the type of field I
am initialising or the name of the corresponding function that provides
default values.  Is there any kind of polymorphic magic that lets me do this
instead?


>  full = do
>     let myOrder = init -- [1]
>              { item = Just init
>                 { itemId = "Something"
>                 }
>              , operation = Just Buy
>              }
>     putStrLn $ show myOrder
>     return ()

Where initOrder and initItem are both replaced with just 'init' and the
compiler works out from the context (ie. the type of the field) what the
types are supposed to be and therefore the actual init function to call?

Thanks,

-John

[1] The second example is silly because there isn't actually any context at
this point, but let's pretend there is.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090605/005c40c9/attachment.html


More information about the Haskell-Cafe mailing list