# Question on style - Implicit parameters

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

```Hi all,=20
Lately I've found implicit parameters to be extremely usefull in many=20
situations.
The most simple and obvious is when you need to calculate some values th=
at=20
depend on specific parameters, in some context where these same parameter=
s=20
constant. There is no poblem if all the calculus are defined in the scope=
of=20
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
where
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=
that=20
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=
wice,=20
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 =
it's=20
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?

J.A.

```