[Haskell-cafe] Disambiguating a Num/RealFrac instance

amindfv at gmail.com amindfv at gmail.com
Wed May 27 00:35:55 UTC 2015


Given:

data GPA = F Float | Excuse String

class ToGPA a where
  giveGPA :: a -> GPA

Is there any way (without IncoherentInstances or Rebindablesyntax) that I can let the user write e.g. "giveGPA 4.0" (and "giveGPA 4") and get back "F 4" without getting type errors that "4.0"'s type is ambiguous? I can guarantee there won't be any additional instances to "ToGPA"

(For my uses, I really (actually!) don't want to make the user write e.g. "F 4.0")

I've gotten this working, once with IncoherentInstances and once with RebindableSyntax, but both of those flags feel pretty dirty.

Thanks,
Tom


More information about the Haskell-Cafe mailing list