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.  Equality instance for lists (Patrick Browne)
   2. Re:  Equality instance for lists (Brandon Allbery)
   3. Re:  Equality instance for lists (Brent Yorgey)
   4.  This code does not work : conversion error (willie ekaputra)
   5. Re:  This code does not work : conversion error (David McBride)
   6. Re:  This code does not work : conversion error (mukesh tiwari)


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

Message: 1
Date: Sat, 30 Nov 2013 22:40:59 +0000
From: Patrick Browne <[email protected]>
To: <[email protected]>
Subject: [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/20131130/b9e6dc26/attachment-0001.html>

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

Message: 2
Date: Sat, 30 Nov 2013 18:01:14 -0500
From: Brandon Allbery <[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:
        <cakfcl4vywofcvzkqpjz5zbx1nefuzjs1codkeps784bmyxp...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Sat, Nov 30, 2013 at 5:40 PM, Patrick Browne <[email protected]>wrote:

> I am trying to write my own simplified class and instances for equality.
> I have trouble with the equality equation for the empty list.
> Even though I can use the [] == [] at the GHCi prompt I cannot use it in
> my equality test.
> How can I make my eq test handle empty lists while staying within the
> context of my current code?.
>

You can't unless you include an Eq constraint on a, since Eq is what
"defines" (==). In your other instance, you use Int and Int has an Eq
instance.

ghci can do it because of extended defaulting: it uses () for a, and there
is an Eq instance for (). But this would not help you in an instance
definition.

-- 
brandon s allbery kf8nh                               sine nomine associates
[email protected]                                  [email protected]
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20131130/3bc1d6b0/attachment-0001.html>

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

Message: 3
Date: Sat, 30 Nov 2013 22:21:27 -0500
From: Brent Yorgey <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Equality instance for lists
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Sat, Nov 30, 2013 at 10:40:59PM +0000, Patrick Browne wrote:
>    Hi,
>    I am trying to write my own simplified class and instances for equality.
>    I have trouble with the equality equation for the empty list.
>    Even though I can use the [] == [] at the GHCi prompt I cannot use it in
>    my equality test.
>    How can I make my eq test handle empty lists while staying within the
>    context of my current code?.
>    Thanks,
>    Pat
> 
>    class Eq1 a where
>     eq :: a -> a -> Bool
>     
>    instance Eq1 Int where
>     eq a b =  a == b
> 
>    instance Eq1 a => Eq1 [a] where
>    -- This line compiles but gives an run time error.
>     eq [] [] =  True

This code does not give a run time error.  The error you are getting
is a type inference error, which has nothing to do with this code.

>     eq [] []

You simply need to give a type annotation on one of the empty lists.

  eq ([] :: [Int]) []

The standard Eq class has some built-in magic support by GHCI
(extended default rules) which means this does not apply in the case
of using == directly.

-Brent


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

Message: 4
Date: Sun, 1 Dec 2013 08:22:12 +0100
From: willie ekaputra <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] This code does not work : conversion
        error
Message-ID:
        <CAMCAAFcOAmtvBMcZwdXW98AawV=rcthjns-ra0jdb6-c_4a...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

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))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20131201/aff32ba9/attachment-0001.html>

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

Message: 5
Date: Sun, 1 Dec 2013 03:12:08 -0500
From: David McBride <[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:
        <can+tr40so-n8jh97tf7a9-uqbk_2wjczdbeta8xqbfhbwpz...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

You just have a few problems.  Where should be lowercase.  The single
quotes should be backticks "`".  You may have some indentation issues.  And
lastly, you have some problems with e and f

   e = round (log $ fromIntegral n)
   f = round (log 2)

Otherwise it seems fine.


On Sun, Dec 1, 2013 at 2:22 AM, willie ekaputra <[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]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20131201/831058e7/attachment-0001.html>

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

Message: 6
Date: Sun, 1 Dec 2013 13:47:03 +0530
From: mukesh tiwari <[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:
        <CAFHZvE9YRH3MTe88bYnY4ac00RaHH=bvqr5wc_lljobpnwm...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

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( See
Infix function )


On Sun, Dec 1, 2013 at 12:52 PM, willie ekaputra
<[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]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20131201/be8cdd98/attachment-0001.html>

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

Subject: Digest Footer

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


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

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

Reply via email to