On Tue, May 5, 2015 at 11:19 AM, Shishir Srivastava <shishir.srivastava@gmail.com> wrote:
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.

Functions are first class and fairly concrete (unless polymorphic) in functional languages. (But I wonder at your example as it seems pretty strange to have firstName be String -> Int.)

    Person { firstName = \name -> whatever }
    Person { firstName = length }

Practical example from xmonad-contrib:

    logHook = dynamicLogWithPP $ defaultPP { ppOutput = hPutStrLn dock }

(two such fields for the price of one! logHook and ppOutput are both function-valued) where dock is from a spawnPipe call that launches something like dzen or xmobar with a pipe connected to its stdin. (See http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Hooks-DynamicLog.html#g:1)

It is worth remembering lazy evaluation; the functions are not evaluated at the time of assignment.

--
brandon s allbery kf8nh                               sine nomine associates
allbery.b@gmail.com                                  ballbery@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net