[Haskell-beginners] Compiler can't deduce Bool as instance of ToField
Kim-Ee Yeoh
ky3 at atamo.com
Thu Aug 15 23:27:55 CEST 2013
On Fri, Aug 16, 2013 at 12:49 AM, Bryan Vicknair <bryanvick at gmail.com>wrote:
> I guess it is because the literal '5' could be an Int or a Float, and the
> type
> system doesn't know.
>
The literal '5' is *known* to be of the *polymorphic* type (Num a => a).
Ints and Floats are monomorphic instances of this polymorphic type. See
http://www.haskell.org/onlinereport/basic.html#numeric-literals
> When I saw that the following does not work...::
>
> bar :: (Show a) => a
> bar = False
>
> ...it made a bit more sense. It seems that if a literal can be considered
> part
> of a typeclass in more than one way, you can declare that literal to be of
> that
> typeclass. However, if there is only one way for a literal to belong to a
> typeclass, then you can't.
>
The part "if a literal can be considered part of a typeclass in more than
one way" isn't how you want to think about them (see link). Good attempt
though.
> I don't have a need for this, but now I'm curious: is there a way to
declare
that all literal numbers in a module are of a certain concrete type?
Something
like -XAllNumbersAreInt8?
You enforce monomorphism by specifying type signatures where appropriate.
In some cases, a light touch is all that's needed because type inference
does the rest.
-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130816/9b92617d/attachment.htm>
More information about the Beginners
mailing list