Question on style - Implicit parameters

Jorge Adriano
Thu, 18 Apr 2002 00:55:05 +0100

Hi all,=20
Lately I've found implicit parameters to be extremely usefull in many=20
 The most simple and obvious is when you need to calculate some values th=
depend on specific parameters, in some context where these same parameter=
constant. There is no poblem if all the calculus are defined in the scope=
those 'constant' parameters, but if you need to define functions outside=20
their scope then you have to pass them as arguments, and sometimes that=20
complicates type signatures.

Now my question.
I've end up in situations where I need to write something like

step :: Inst-> Train->Inst
step inst train =3D changeInst deltaW deltaV inst
 deltaW =3D someSemiConst1 with ?inst=3Dinst; ?train train
 deltaV =3D someSemiConst2 with ?inst=3Dinst; ?train train

Ok the problem is that both deltaV and deltaW are assigned some constants=
implicitly depend on the arguments 'inst' and 'train'.
Now imagine that=20

someSemiConst1 =3D f n
someSemiConst2 =3D g n

for some n that also depends implicitly on 'inst' and 'train'.
In this case 'n' would (could? haven't actually tried it) be calculated t=
one fro the first semiConst, another for the second.

It would be nice to have something like
with ?inst=3Dinst; ?train train
 deltaW =3D someSemiConst1=20
 deltaV =3D someSemiConst2=20

My solution was to define some function
(deltaW, deltaV)=3DcalculateDeltas with ?inst=3Dinst; ?train=3Dtrain
And in this function I simple does
(deltaW, deltaV)=3D (someSemiConst1, someSemiConst2)

In case you're wondering, why not just call the 'step' function bounding =
context to 'inst' and 'train'. It doesn't makes much sense to me in this=20
case, becouse the whole purpose of this function is to change a 'inst'=20
acording to some 'train' (in fact it is beeing used in a foldl).

How do you usually handle this situations?
Is there an elegant solution for this?