Passing values taking implicit parameters

Jorge Adriano jadrian@mat.uc.pt
Thu, 31 Jan 2002 12:50:03 +0000


> > 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 -> ..

I using that same strategy, but instead I'm passing that Parameters datatype 
as an implicit parameter. Like you said, sometimes the code gets really 
messy, many times you also have to add Parameters as a return value...
fun :: Parameters -> ... -> (ReturnValue,Parameters)

And sometimes I rather define more than one container because the Parameters 
have completely different purposes (and that would make the code even 
uglier).


> BEGIN wishlist:
<snip>
My whilist for records. 'Records' provide projection functions, but IMO that 
is not enough, it would be really handy to have some 'update' and 'apply 
field' functions provided automaticly for each field. 
I always find myself having to write this functions by hand for each field, 
because I just can't do without them, and if you have 2 records with 6 fields 
each, that means 2*2*6 functions = 24 functions... wasted time, more 
oputunities to make dumb mistakes defining similar functions, tiresome to add 
and delete record fields... you get the picture.

I think it i spretty ovious why you need them, anyway the two main reasons 
are, 

1.)
Imagine you have:
> data Somedata = C{c1, c2, c3, c4, c5, c6 :: Int}

Every time you want to apply some function to a field you'll have to write 
something like:
> c{c1=f (c1 c)}  -- now how ugly is this :-)

2.)
I keep finding myself defining functions like
> someChange::((Int->Int)->Somedata->Somedata)->...->Somedata

The idea is to recieve a 'apply field function', a couple of other 
parameters, and update the field defined by the apply field function acording 
to those other parameters. Without the 'apply field' functions, you'd have to 
write the same code for each of the fields.

J.A.