Passing values taking implicit parameters

Johannes Waldmann joe@isun.informatik.uni-leipzig.de
Thu, 31 Jan 2002 09:41:20 +0100 (MET)


> I'd like write a function taking values with implicit parameters.  

This may not be exactly what you're after, but ..

I understand the need for implicit parameters
(sometimes when my functions seem to need A LOT of parameters, 
the code looks really messy, and adding another parameter is a mess as well,
especially since it often affects unrelated functions
that have to pass down the additional parameter)
but often I use the following work-around: I define a container type

> data Parameters = Parameters { foo :: .., bar :: , .. }

and then my functions just read

> fun :: Parameters -> ..


BEGIN wishlist:

Now, can we please have defaults in data declarations? As in

> data Foo = { host :: String, port = 9999 :: Int }

Better still, can we construct default values, 
using values of other components, as in

> data Tree = { top :: Item , left :: Tree, .. 
>	      , size = size (left self) + .. }

This would require some means to refer to "the record under construction"
(e. g. `self')

The above example also shows that it should in fact be forbidden
to override the `size' component.

Perhaps it would be even better if we could define `size' later
(not inside the data declaration).

Note that some (most?) of the above is available for type *classes*,
instead of types.

Best regards,
-- 
-- Johannes Waldmann ---- http://www.informatik.uni-leipzig.de/~joe/ --
-- joe@informatik.uni-leipzig.de -- phone/fax (+49) 341 9732 204/252 --