[Haskell-cafe] noob question
Ben
thefunkslists at gmail.com
Mon Feb 25 19:32:32 EST 2008
On Feb 25, 2008, at 4:11 PM, Philippa Cowderoy wrote:
> On Mon, 25 Feb 2008, Ben wrote:
>
>> <interactive>:1:8:
>> Ambiguous type variable `t' in the constraints:
>> `Fractional t' arising from a use of `/' at <interactive>:1:8-10
>> `Integral t' arising from a use of `^' at <interactive>:1:7-15
>> Probable fix: add a type signature that fixes these type
>> variable(s)
>>
>
> / doesn't do integer division, so from there it concludes that you're
> working with a Fractional type - Haskell never coerces behind your
> back,
> so not only the result of / but also its parameters are Fractional.
>
> ^ only works for Integral types. You might consider that a little
> arbitrary, but hey - it's mostly like that because it's much easier to
> raise something to an integer power.
>
> There's no default it can pick that's both Fractional and Integral,
> so it
> doesn't know what type the expression should have and it's asking
> you to
> tell it ("add a type signature that fixes these type variable(s)"). In
> practice you won't be able to unless you've got a broken number type
> handy, but that's the way things go.
Ok, that makes sense. There's no num k that's both Fractional and
Integral, where as in the case where I had the number literals, those
were two different instances. What's the usual way of working around
this? Something like
(\k -> (1/ fromInteger k) ^ k) 3
?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080225/b5b717a5/attachment.htm
More information about the Haskell-Cafe
mailing list