[Haskell] "strange" behavior of Implicit Parameters
simonpj at microsoft.com
Mon Feb 27 03:50:49 EST 2006
Look at the type of (???)
(???) :: a -> (a->b) -> b
Nothing about ?foo in there. You're passing a *monomorphic* function
to (???), so fun is partially applied to ?foo before calling (???).
| -----Original Message-----
| From: haskell-bounces at haskell.org [mailto:haskell-bounces at haskell.org]
On Behalf Of Eike Scholz
| Sent: 27 February 2006 00:14
| To: haskell at haskell.org
| Subject: [Haskell] "strange" behavior of Implicit Parameters
| I have just a short question, about the semantics of Implicit
| 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
| Could it be a bug?
| Reducing it my way would be very useful for combinator-libraries,
| 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
| so error annotations will accumulate and it would be easy to resolve
| runtime errors.
| best regards
| Eike Scholz
| Haskell mailing list
| Haskell at haskell.org
More information about the Haskell