On 26 January 2006 16:07, John Hughes wrote: > Simon Marlow wrote: > >> I wonder if there's an alternative solution along these lines: >> >> - We use ParialTypeSignatures to make bindings monomorphic: >> >> >> http://haskell.galois.com/cgi-bin/haskell-prime/trac.cgi/wiki/PartialTyp >> eSigs >> >> eg. >> >> x :: _ >> x = (+1) >> >> - we make it a static error for a variable bound by a simple pattern >> binding ("x = e") to be overloaded, unless a type signature is >> given. The error message would explain the problem, and how to >> fix it. Alternatively, we make it a strong warning. >> >> It seems to me that the partial type signatures extension provides a >> lot of bang for the buck - it gives us a way out of the MR in >> addition to partial type signatures. >> > I don't like this. Once students start dropping type signatures (which > they do > pretty soon for local variables in where-clauses), they would > sometimes-- unpredictably as far as they're concerned--get an error > message telling them they must put one back in again, but it's enough > to write x :: _. Can > you imagine > explaining to an average student in the first year why they MUST put > in a type signature, but it doesn't need to include a type???
Understood, but what about when the student writes '=' instead of ':=' by mistake - most of the time it'll work! But occasionally they fall foul of the reason we had the MR in the first place. Presumably the compiler should emit a noisy warning, but continue anyway? Won't that be confusing? How about an even simpler solution: *All* pattern and variable bindings are monomorphic unless a type signature is given. I wonder how much code this would break? It can't be too bad, because John is suggesting using := for variable bindings everywhere as a starting point. Also, SML users live with something very similar. How often do we really need polymorphism in a variable or pattern binding? I'm guessing probably not that often, because by far the most common use of polymorphism is in functions. You lose if you write mymap = map or mynil = [] and then try to use those at more than one type, but I'm guessing that's quite rare, and you can still give a type signature. I'd be very interested to tweak this in GHC and see how much code still passes the type checker. Cheers, Simon _______________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://haskell.org/mailman/listinfo/haskell-prime