Send Beginners mailing list submissions to
        beginners@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-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@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 <alexan...@chenjia.nl>
To: beginners@haskell.org
Subject: [Haskell-beginners] why doesn't this work?
Message-ID: <675050120.318296.1578495680...@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" <ol...@ocharles.org.uk>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] why doesn't this work?
Message-ID: <ef1efd77-6d1c-4a07-94d5-d5125947d...@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 <utpri...@gmail.com>
To: Alexander Chen <alexan...@chenjia.nl>,  The Haskell-Beginners
        Mailing List - Discussion of primarily beginner-level topics related
        to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] why doesn't this work?
Message-ID:
        <canjdmkjmrajergqere4cr0gmasqh2dnh36pw4hvw_ekdu3c...@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 <alexan...@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@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@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

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

Reply via email to