On 23 April 2012 20:34, J. Garrett Morris <jgmor...@cs.pdx.edu> wrote: > On Mon, Apr 23, 2012 at 9:58 AM, Yitzchak Gale <g...@sefer.org> wrote: >> In addition, OverloadedStrings is unsound. > > No. OverloadedStrings treats string literals as applications of > fromString to character list constants. fromString can throw errors, > just like fromInteger; this is no less sound than any Haskell function > throwing an exception.
But it would be safer if those errors were moved to compile time by treating overloaded literals as Template Haskell splices. As in: 1 would be translated to: $(fromIntegerLit 1) where: class FromIntegerLit a where fromIntegerLit :: Integer -> Q (Exp a) (this assumes that Exp is parameterized by the type of the value it splices to which is currently not the case. However you can work around this by using a Proxy or Tagged value.) An instance for Integer is trivial: instance FromIntegerLit Integer where fromIntegerLit = litE . integerL The extra safety comes when giving an instance for natural numbers, for example: newtype Nat = Nat Integer instance FromIntegerLit Nat where fromIntegerLit n | n < 0 = error "Can't have negative Nats" | otherwise = 'Nat `appE` fromIntegerLit n Note that the error will be thrown at compile time when the user has written a negative Nat literal. Regards, Bas _______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users