Hi all,
Lately I've found implicit parameters to be extremely usefull in many
situations.
The most simple and obvious is when you need to calculate some values that
depend on specific parameters, in some context where these same parameters
constant. There is no poblem if all the calculus are defined in the scope of
those 'constant' parameters, but if you need to define functions outside
their scope then you have to pass them as arguments, and sometimes that
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 = changeInst deltaW deltaV inst
where
deltaW = someSemiConst1 with ?inst=inst; ?train train
deltaV = someSemiConst2 with ?inst=inst; ?train train
---------
Ok the problem is that both deltaV and deltaW are assigned some constants that
implicitly depend on the arguments 'inst' and 'train'.
Now imagine that
someSemiConst1 = f n
someSemiConst2 = 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 twice,
one fro the first semiConst, another for the second.
It would be nice to have something like
with ?inst=inst; ?train train
{
deltaW = someSemiConst1
deltaV = someSemiConst2
}
My solution was to define some function
(deltaW, deltaV)=calculateDeltas with ?inst=inst; ?train=train
And in this function I simple does
(deltaW, deltaV)= (someSemiConst1, someSemiConst2)
In case you're wondering, why not just call the 'step' function bounding it's
context to 'inst' and 'train'. It doesn't makes much sense to me in this
case, becouse the whole purpose of this function is to change a 'inst'
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.
_______________________________________________
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe