[Haskell-beginners] Using Fractional Type

David James dj112358 at outlook.com
Sun Feb 21 08:41:52 UTC 2021


Also, I wonder if you’re typing:
> 5 mod 2

This does give a FlexibleContexts error. You should type either:
> mod 5 2
or
> 5 `mod` 2

(or, using mod’ as suggested):
> 5.5 `mod'` 1.3

You can read about prefix and infix notation here<http://learnyouahaskell.com/starting-out>.

David.

From: Bob Ippolito<mailto:bob at redivi.com>
Sent: 20 February 2021 23:11
To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell<mailto:beginners at haskell.org>
Subject: Re: [Haskell-beginners] Using Fractional Type

I think what you're looking for is the mod' function from Data.Fixed. The mod function only works with Integral types, FlexibleContexts wouldn't be helpful for this.


On Sat, Feb 20, 2021 at 12:00 PM A. Mc. <47dragonfyre at gmail.com<mailto:47dragonfyre at gmail.com>> wrote:
Hello,

I need to create a function that does: mod (recip x) y.  However, I am getting all kinds of errors with the type signature.  Is there a better way to use Fractional type than needing to enable FlexibleContexts?  What do I need to do to still make use of Haskell's type system, but also still be able to perform operations such as reciprocal (and division into fractions for that matter).

Thanks in advance and thank you for your time.
_______________________________________________
Beginners mailing list
Beginners at haskell.org<mailto:Beginners at haskell.org>
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20210221/9dc4c60d/attachment.html>


More information about the Beginners mailing list