[Haskell-beginners] Beginners Digest, Vol 139, Issue 2

Alex Zarebski aezarebski at gmail.com
Thu Jan 9 23:51:29 UTC 2020


If the goal is to filter a list for numbers which are multiples of some
other number, perhaps the =mod= function would be a neater way to do this.

It is part of the Prelude with documentation here:
https://hackage.haskell.org/package/base-4.12.0.0/docs/Prelude.html#v:mod

On Thu, Jan 9, 2020 at 12:01 PM <beginners-request at haskell.org> wrote:

> Send Beginners mailing list submissions to
>         beginners at haskell.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> or, via email, send a message with subject or body 'help' to
>         beginners-request at haskell.org
>
> You can reach the person managing the list at
>         beginners-owner at haskell.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Beginners digest..."
>
>
> Today's Topics:
>
>    1.  why doesn't this work? (Alexander Chen)
>    2. Re:  why doesn't this work? (Oliver Charles)
>    3. Re:  why doesn't this work? (Ut Primum)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Wed, 8 Jan 2020 16:01:20 +0100 (CET)
> From: Alexander Chen <alexander at chenjia.nl>
> To: beginners at haskell.org
> Subject: [Haskell-beginners] why doesn't this work?
> Message-ID: <675050120.318296.1578495680883 at ichabod.co-bxl>
> Content-Type: text/plain; charset="utf-8"
>
> hi,
>
> for a List comprehension I want to only include the integers of a
> division. In my beginners mind this should work:
>
> (round (x / y)) == (x / y)
>
> however, i get a nontrivial error blurp.
>
> what am i doing wrong?
>
> best,
>
> Alexander
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://mail.haskell.org/pipermail/beginners/attachments/20200108/90275f59/attachment-0001.html
> >
>
> ------------------------------
>
> Message: 2
> Date: Wed, 08 Jan 2020 16:37:47 +0000
> From: "Oliver Charles" <ollie at ocharles.org.uk>
> To: beginners at haskell.org
> Subject: Re: [Haskell-beginners] why doesn't this work?
> Message-ID: <ef1efd77-6d1c-4a07-94d5-d5125947df2a at www.fastmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> On Wed, 8 Jan 2020, at 3:01 PM, Alexander Chen wrote:
> > hi,
> >
> > for a List comprehension I want to only include the integers of a
> division. In my beginners mind this should work:
> >
> > (round (x / y)) == (x / y)
> >
> > however, i get a nontrivial error blurp.
>
> Could you share what the "nontrivial error blurp" is? It will be easier
> for people to reply to you if they can see the problem without
> having to reproduce it manually.
>
> Ollie
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://mail.haskell.org/pipermail/beginners/attachments/20200108/57c13db7/attachment-0001.html
> >
>
> ------------------------------
>
> Message: 3
> Date: Wed, 8 Jan 2020 18:50:35 +0100
> From: Ut Primum <utprimum at gmail.com>
> To: Alexander Chen <alexander at chenjia.nl>,  The Haskell-Beginners
>         Mailing List - Discussion of primarily beginner-level topics
> related
>         to Haskell <beginners at haskell.org>
> Subject: Re: [Haskell-beginners] why doesn't this work?
> Message-ID:
>         <
> CANjDmKJMRAjErGQeRE4cr0GmASQh2Dnh36PW4hvw_Ekdu3CNaQ at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Hi,
> I think the problem is in the types.
> If you look at the type of the function round, you can see its result is an
> Integral:
>
> >> :t round
> round :: (Integral b, RealFrac a) => a -> b
>
> The result of the division x/y, instead, is a Fractional, and you cannot
> test equality between two things of different types.
> To solve the problem you can do a type cast, by converting the Integral to
> a Num, using fromInteger:
>
> (fromInteger (round (x/y))) == (x/y)
>
> This should work.
>
> Cheers,
> Ut
>
>
>
>
> Il giorno mer 8 gen 2020 alle ore 16:01 Alexander Chen <
> alexander at chenjia.nl>
> ha scritto:
>
> > hi,
> >
> > for a List comprehension I want to only include the integers of a
> > division. In my beginners mind this should work:
> >
> > (round (x / y)) == (x / y)
> >
> > however, i get a nontrivial error blurp.
> >
> > what am i doing wrong?
> >
> > best,
> >
> > Alexander
> >
> >
> >
> > _______________________________________________
> > Beginners mailing list
> > 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/20200108/4efa2af4/attachment-0001.html
> >
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
> ------------------------------
>
> End of Beginners Digest, Vol 139, Issue 2
> *****************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20200109/90398f40/attachment.html>


More information about the Beginners mailing list