[Haskell] Extensible records: Static duck typing

Jason Dusek jason.dusek at gmail.com
Sun Feb 10 15:45:57 EST 2008


On Feb 5, 2008 2:28 AM, Bulat Ziganshin <bulat.ziganshin at gmail.com> wrote:
> this principle allows to build programs in quick and easy way: we just
> add to objects implementations of all the methods required:
>
> e = new Entry {label := "Hi",
>                color := blue,
>                getValue := getEntryValue,
>                setValue := setEntryValue}
>
> e.display      -- uses color/label properties
> e.saveToFile   -- uses getValue property

I'm new to all this -- I can't figure out why we want to put
methods inside of records. Why don't we define a module instead?

module EntryModule where

data Entry = Entry String Color

display (Entry s c) = do someIOMagic

saveToFile (Entry s c) = do someOtherIOMagic

If we want a more generic approach -- where a function excepts
one of many kinds of data -- than is a type class not suitable?

-- 
_jsn


More information about the Haskell mailing list