[Haskell-beginners] Data type

Brandon Allbery allbery.b at gmail.com
Tue May 5 15:49:58 UTC 2015


On Tue, May 5, 2015 at 11:38 AM, Shishir Srivastava <
shishir.srivastava at gmail.com> wrote:

> I was going to follow up my question with the possible practical use of
> why and where someone would use such a construct to wrap a function inside
> a new data-type.
>
> For all that matters I could have used 'length' function directly to get
> the same output.
>

Because you want a different function for each value, typically. Continuing
with the DynamicLog example, I have two different uses of DynamicLog in my
xmonad config; one feeds an EWMH panel from the logHook, so it sets

    defaultPP { {- ... -}, ppOutput = dbusOutput ch }

where ch was previously associated with a dbus endpoint. This is executed
whenever the focused window changes or the current workspace changes.

The second is in a keybinding I use for debugging and outputs to the
session log (~/.xsession-errors):

    defaultPP { {- ... -}, ppOutput = hPutStrLn stderr }

(The ellipsis comments customize the value in other ways not important
here.)

You might think of this use of record syntax as being the Haskell version
of "named parameters" (as distinct from positional parameters) present in
some other languages.

-- 
brandon s allbery kf8nh                               sine nomine associates
allbery.b at gmail.com                                  ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150505/80fa9e62/attachment-0001.html>


More information about the Beginners mailing list