User-Controlled Defaulting Proposals?
Hey all, I wish Haskell gave typeclass authors more control over defaulting. I see there are a number of proposals here: https://ghc.haskell.org/trac/haskell-prime/wiki/Defaulting Are any of these being actively pursued? If not, why not, and if so, what proposals will potentially make it into Haskell eventually? Just curious, Andrew
Mostly, I am curious about general efforts in the area. I personally would like a mechanism by which type class instances may be used for type inference. Specifically, I wish there were some mechanism by which I could say, if there is only one instance of a typeclass available, choose it and proceed with type inference. This is somewhat what defaulting currently allows. Here is some code that I would like to "emulate" class FromInt a where fromInt :: Int -> a instance FromInt String where fromInt = show instance FromInt Int where fromInt = id class Go a where go :: a -> IO () instance Go Int where go = print -- No type signature necessary anywhere main = go $ fromInt 3 Here, I would like `fromInt 3` to be defaulted to `Int`, as that is the only possible instance that `Go` allows; once it is defaulted, then type inference can continue as normal, choosing the appropriate `FromInt` instance. (Of course, I do not mean for the code as written above to have backwards incompatible behaviour; instead probably some syntactic changes would indicate that "Go" is somehow defaultable, etc etc) Note that this proposal is far from "fleshed out" and I don't have any suggestions for how Haskell might move in such a direction in the immediate future; I am more just curious whether work has been done in this area or what other options may be. Using typeclass instances for type resolution would allow clever design to get rid of "ambiguous variable" errors, and allow us to write cleaner code without as many type annotations (which is what defaulting allows for numeric literals). -- Andrew On Tue, Dec 30, 2014 at 8:20 AM, Kim-Ee Yeoh <ky3@atamo.com> wrote:
I wish Haskell gave typeclass authors more control over defaulting.
If you could flesh out your case more, social momentum will build more rapidly to push things through.
What concrete problem are you trying to solve with finer-grained defaulting?
-- Kim-Ee
participants (2)
-
Andrew Gibiansky -
Kim-Ee Yeoh