[Haskell] "strange" behavior of Implicit Parameters
Eike Scholz
eikescholz at gmx.de
Sun Feb 26 19:13:56 EST 2006
Hi,
I have just a short question, about the semantics of Implicit parameters
on GHC 6.4.
Given the following code:
> (???) x f
> = let ?foo = 1337
> in f x
> fun :: (?foo::Int,Show x) => x -> String
> fun x = "x = "++(show x)++"; ?foo = "++(show ?foo)
> test = let ?foo = 23
> in 42 ??? fun
I would expect:
test == "x = 42; ?foo = 1337"
Because I thought, that it gets reduced like:
let ?foo = 23 in 42 ??? fun
~> let ?foo = 23 in (let ?foo = 1337 in fun 42)
~> ...
~> "x = 42; ?foo = 1337"
however I get
"x = 42; ?foo = 23"
in ghci.
Is there a special reason, why the implicit parameter is reduced first?
Could it be a bug?
Reducing it my way would be very useful for combinator-libraries, since
it could be used passing around state info, or simple debug text, that
tells where a Runtime-error occured?
an odd example:
> undef = error ?errstr
> (<?>) x s = let ?errstr = ?errstr++"\n"++s in x -- annotate error tags
so error annotations will accumulate and it would be easy to resolve
runtime errors.
best regards
Eike Scholz
More information about the Haskell
mailing list