Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

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

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Equality instance for lists (Patrick Browne)
   2. Re:  This code does not work : conversion error (Graham Gill)
   3.  Overflow when reading C types (Patrick Redmond)
   4. Re:  Overflow when reading C types ([email protected])
   5. Re:  Overflow when reading C types ([email protected])
   6.  Understanding inheritance (Patrick Browne)


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

Message: 1
Date: Sun, 1 Dec 2013 12:52:42 +0000
From: Patrick Browne <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Equality instance for lists
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20131201/380648fa/attachment-0001.html>

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

Message: 2
Date: Sun, 01 Dec 2013 09:16:58 -0500
From: Graham Gill <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] This code does not work : conversion
        error
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"; Format="flowed"

Once you've made those changes, you also need

n `mod` 2^k

instead of 2^k `mod` n.

Finally, using e `div` f, and round() in the definitions of e and f, to 
give you the largest power of 2 dividing n doesn't work correctly. For 
example:
maxexp2 4 = 1 (should be 2)
maxexp2 16 = 3 (should be 4)
maxexp2 18 = 0 (should be 1)
maxexp2 28 = 0 (should be 2)

But that's not a Haskell error, that's a problem with the algorithm.

(Sorry if I've misinterpreted what you're trying to do.)

Graham

On 01/12/2013 3:17 AM, mukesh tiwari wrote:
> Hi Willie,
> Here is the code  modified
> maxexp2:: Int -> Int
> maxexp2 n
>     |n== 0 || 2^k `mod` n /=0 =0
>     |otherwise = k
>           where
>             k = e `div` f
>             e  = round  ( log ( fromIntegral n ) )
>             f = round ( (log 2.0 ))
>
> When you computing  k then use backticks (`) [1]  not the single quote 
> ( ' )
>
> [1] http://book.realworldhaskell.org/read/functional-programming.html( 
> <http://book.realworldhaskell.org/read/functional-programming.html%28> 
> See Infix function )
>
>
> On Sun, Dec 1, 2013 at 12:52 PM, willie ekaputra 
> <[email protected] <mailto:[email protected]>> wrote:
>
>     Hi everyone !
>     I am newbie and I made this code for counting k, so that 2^k
>     divisor of n.Somehow it doesn't work.
>     Anyone knows what is  wrong?
>
>     Regards and thanks.
>     Wili.
>
>     maxexp2:: Int -> Int
>     maxexp2 n
>         |n== 0 || 2^k 'mod' n /=0 =0
>         |otherwise = k
>               Where
>                k= e ' div' f
>                e=round (fromIntegral (log n))
>                 f = round (fromIntegral (log 2))
>
>
>     _______________________________________________
>     Beginners mailing list
>     [email protected] <mailto:[email protected]>
>     http://www.haskell.org/mailman/listinfo/beginners
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20131201/0042b947/attachment-0001.html>

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

Message: 3
Date: Mon, 2 Dec 2013 11:30:50 +1300
From: Patrick Redmond <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Overflow when reading C types
Message-ID:
        <cahuea4f6vdqlefrjzme+rvmla5+7fz+xbw4nn9vmjl67tpp...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Prelude> import Foreign.C.Types
Prelude Foreign.C.Types> read "-10" :: CUInt
4294967286
Prelude Foreign.C.Types> read "300" :: CChar
44

This seems like a bug. Shouldn't these result in some kind of read error?

The values expressed as strings are simply not part of the type they
are being parsed into. However, Haskell seems to parse them into an
arbitrarily wide numeric type, and then overflow them down to the
correct size.

What's the rationale here?


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

Message: 4
Date: Mon, 2 Dec 2013 11:38:33 +1300
From: [email protected]
To: [email protected]
Subject: Re: [Haskell-beginners] Overflow when reading C types
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Mon, Dec 02, 2013 at 11:30:50AM +1300, Patrick Redmond wrote:
> Prelude> import Foreign.C.Types
> Prelude Foreign.C.Types> read "-10" :: CUInt
> 4294967286
> Prelude Foreign.C.Types> read "300" :: CChar
> 44
> 

CUInt? I would try CInt instead.

A.


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

Message: 5
Date: Mon, 2 Dec 2013 12:09:30 +1300
From: [email protected]
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Overflow when reading C types
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Mon, Dec 02, 2013 at 11:38:33AM +1300, [email protected] wrote:
> On Mon, Dec 02, 2013 at 11:30:50AM +1300, Patrick Redmond wrote:
> > Prelude> import Foreign.C.Types
> > Prelude Foreign.C.Types> read "-10" :: CUInt
> > 4294967286
> > Prelude Foreign.C.Types> read "300" :: CChar
> > 44
> > 
> 
> CUInt? I would try CInt instead.
> 

Whoops, that is not related to the original question, sorry.



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

Message: 6
Date: Mon, 2 Dec 2013 00:08:42 +0000
From: Patrick Browne <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Understanding inheritance
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20131202/ce7857ce/attachment.html>

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


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

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

Reply via email to