Re: Beginners Digest, Vol 139, Issue 2

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: Beginners Digest, Vol 139, Issue 2

Alex Zarebski
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 <[hidden email]> wrote:
Send Beginners mailing list submissions to
        [hidden email]

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
        [hidden email]

You can reach the person managing the list at
        [hidden email]

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 <[hidden email]>
To: [hidden email]
Subject: [Haskell-beginners] why doesn't this work?
Message-ID: <[hidden email]-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" <[hidden email]>
To: [hidden email]
Subject: Re: [Haskell-beginners] why doesn't this work?
Message-ID: <[hidden email]>
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 <[hidden email]>
To: Alexander Chen <[hidden email]>,  The Haskell-Beginners
        Mailing List - Discussion of primarily beginner-level topics related
        to Haskell <[hidden email]>
Subject: Re: [Haskell-beginners] why doesn't this work?
Message-ID:
        <[hidden email]>
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 <[hidden email]>
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
> [hidden email]
> 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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 139, Issue 2
*****************************************

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners