The madness of implicit parameters: cured?
Ashley Yakeley
ashley@semantic.org
Sun, 03 Aug 2003 02:35:10 -0700
In article <Pine.LNX.4.21.0308020030420.6841-100000@dark.darkweb.com>,
Ben Rudiak-Gould <benrg@dark.darkweb.com> wrote:
> The final straw was:
>
> Prelude> let ?x = 1 in let g = ?x in let ?x = 2 in g
> 1
> Prelude> let ?x = 1 in let g () = ?x in let ?x = 2 in g ()
> 2
>
> This is insanity. I can't possibly use a language feature which behaves in
> such a non-orthogonal way.
It's a type inference problem:
Prelude> let ?x = 1 in let {g :: Int;g = ?x;} in let ?x = 2 in g
1
Prelude> let ?x = 1 in let {g :: (?x :: Int) => Int;g = ?x;} in let
?x = 2 in g
2
Prelude> let ?x = 1 in let {g :: () -> Int;g () = ?x;} in let ?x = 2
in g ()
1
Prelude> let ?x = 1 in let {g :: (?x :: Int) => () -> Int;g () =
?x;} in let ?x = 2 in g ()
2
The type of g is ambiguous, and GHC arbitrarily goes with different
options in the two different cases. Ideally, GHC would complain about
the ambiguity.
IIRC with -fglasgow-exts turned on there are other cases when GHC infers
the "wrong" type if you don't specify it. This is because with
higher-order types, there isn't necessarily an inferable "most general"
type for some expressions.
But implicit parameters work very well if you have the type of
everything specified. I use them extensively in HScheme without trouble.
--
Ashley Yakeley, Seattle WA