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:  Type Tree variables (Ozgur Akgun)
   2.  Class instance for a type without a parameter (Peter Hall)
   3. Re:  Type Tree variables (Ozgur Akgun)
   4. Re:  Class instance for a type without a  parameter (Ozgur Akgun)
   5. Re:  Class instance for a type without a  parameter
      (Daniel Fischer)
   6.  A "show" error (bahad?r altan)
   7. Re:  A "show" error (Ozgur Akgun)


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

Message: 1
Date: Sun, 11 Mar 2012 15:50:25 +0000
From: Ozgur Akgun <[email protected]>
Subject: Re: [Haskell-beginners] Type Tree variables
To: bahad?r altan <[email protected]>,        Haskell Beginners
        <[email protected]>
Message-ID:
        <CALzazPAmeVdU19Z=Ey7q8a5TCj=Pq9biwpjX=me_y2_itqa...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

What's the error you get?

On 11 March 2012 15:37, bahad?r altan <[email protected]> wrote:

> I tried "f" function but it always give errors. Thanks anyway..
>

Ozgur
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20120311/1d548892/attachment-0001.htm>

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

Message: 2
Date: Sun, 11 Mar 2012 15:57:30 +0000
From: Peter Hall <[email protected]>
Subject: [Haskell-beginners] Class instance for a type without a
        parameter
To: [email protected]
Message-ID:
        <CAA6hAk5a-1HDziyNnKhGxJZce9i8=shgt1iqxx1yy2qjmm7...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

Can someone remind me why I can't do this:


    data Digit = D0 | D1 | D2 | D3 | D4 | D5 | D6 | D7 | D8 | D9
        deriving (Eq, Ord, Show)

    instance Num [Digit] where ...  -- This isn't allowed


I could make Num a => [a] an instance of Num, but I can't make Digit
also an instance of Num because D8 + D5 is not a digit. So then I
could introduce a ConvertableToNum class, but I feel like I'd be
heading down a path with a lot of unnecessary extra type classes.

Thanks,

Peter



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

Message: 3
Date: Sun, 11 Mar 2012 16:04:50 +0000
From: Ozgur Akgun <[email protected]>
Subject: Re: [Haskell-beginners] Type Tree variables
To: bahad?r altan <[email protected]>,        Haskell Beginners
        <[email protected]>
Message-ID:
        <calzazpbft_4_8v8hdt64vyvj5drwdcsu6hwsvqfm8m4m6id...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

You need to provide a Show instance for your data type. The easiest way is
to add 'deriving Show' at the end of your data type declaration.

The errors you get aren't to do with the function f.

On 11 March 2012 16:01, bahad?r altan <[email protected]> wrote:

> These are the ones I get, they are the same but they have different inputs
> :
>
> Main> f (Branch 12 (Branch 7 (Branch 3 Empty Empty) (Branch 10 Empty
> Empty)) (Branch 24 Empty Empty))
> ERROR - Cannot find "show" function for:
> *** Expression : f (Branch 12 (Branch 7 (Branch 3 Empty Empty) (Branch 10
> Empty Empty)) (Branch 24 Empty Empty))
> *** Of type    : (Integer,Integer,Tree,Tree,Integer,Tree,Tree)
>
>
> Main> f (Branch 13 (Branch 2 Empty Empty) (Branch 48 Empty Empty))
> ERROR - Cannot find "show" function for:
> *** Expression : f (Branch 13 (Branch 2 Empty Empty) (Branch 48 Empty
> Empty))
> *** Of type    : (Integer,Integer,Tree,Tree,Integer,Tree,Tree)
>
> To be clear, I need to get a tree as an input. I mean the output should be
> like this :
>
> f (Branch a (Branch b (Branch d Empty Empty) (Branch e Empty Empty))
> (Branch c Empty Empty)) = Branch b (Branch d Empty Empty) (Branch a (Branch
> e Empty Empty) (Branch c Empty Empty))
>
>
>  Thank you very much for helping me I really appreciate it :)
>
>   ------------------------------
> *From:* Ozgur Akgun <[email protected]>
> *To:* bahad?r altan <[email protected]>; Haskell Beginners <
> [email protected]>
> *Sent:* Sunday, 11 March 2012, 17:50
>
> *Subject:* Re: [Haskell-beginners] Type Tree variables
>
> What's the error you get?
>
> On 11 March 2012 15:37, bahad?r altan <[email protected]> wrote:
>
> I tried "f" function but it always give errors. Thanks anyway..
>
>
> Ozgur
>
>
>


-- 
Ozgur Akgun
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20120311/d603b72b/attachment-0001.htm>

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

Message: 4
Date: Sun, 11 Mar 2012 16:09:17 +0000
From: Ozgur Akgun <[email protected]>
Subject: Re: [Haskell-beginners] Class instance for a type without a
        parameter
To: [email protected]
Cc: [email protected]
Message-ID:
        <CALzazPDci1y4Krxv=1KXagmRFqscC=sup+as4uwncruwl5b...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi,

On 11 March 2012 15:57, Peter Hall <[email protected]> wrote:

> Can someone remind me why I can't do this:
>
>
>    data Digit = D0 | D1 | D2 | D3 | D4 | D5 | D6 | D7 | D8 | D9
>        deriving (Eq, Ord, Show)
>
>    instance Num [Digit] where ...  -- This isn't allowed
>

Why is it not allowed? Yes, it needs FlexibleInstances, but this is a
fairly common language extension so shouldn't be a big problem for most use
cases.

The error message generated by ghc should tell you about this. Following is
what I get for example:

Illegal instance declaration for `Num [Digit]'
      (All instance types must be of the form (T a1 ... an)
       where a1 ... an are *distinct type variables*,
       and each type variable appears at most once in the instance head.
       Use -XFlexibleInstances if you want to disable this.)
    In the instance declaration for `Num [Digit]'

HTH,
Ozgur
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20120311/391f36d1/attachment-0001.htm>

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

Message: 5
Date: Sun, 11 Mar 2012 17:10:56 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Class instance for a type without a
        parameter
To: [email protected], [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain;  charset="iso-8859-1"

On Sunday 11 March 2012, 16:57:30, Peter Hall wrote:
> Can someone remind me why I can't do this:
> 
> 
>     data Digit = D0 | D1 | D2 | D3 | D4 | D5 | D6 | D7 | D8 | D9
>         deriving (Eq, Ord, Show)
> 
>     instance Num [Digit] where ...  -- This isn't allowed
> 

It's because the language standard says that the types in the instance head 
must be of the form

T a1 ... ak

with `T' a type constructor and the ai distinct type variables. Why that 
is, I don't know.

You can make an

instance Num [Digit] where ...

if you enable

{-# LANGUAGE FlexibleInstances #-}

That's a harmless extension allowing instances of that form.



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

Message: 6
Date: Sun, 11 Mar 2012 19:10:28 +0000 (GMT)
From: bahad?r altan <[email protected]>
Subject: [Haskell-beginners] A "show" error
To: "[email protected]" <[email protected]>
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

Hi,?
I'm trying to process on a tree with this function :

f (Branch x (Branch y y1 y2) (Branch z z1 z2)) = (x,y,y1,y2,z,z1,z2)


and my tree declaration is this :?

data Tree = Empty | Branch Integer Tree Tree deriving (Show)

And I'm getting this error :?

Main> f (Branch 12 (Branch 15 Empty Empty) (Branch 28 Empty Empty))
ERROR - Cannot find "show" function for:
*** Expression : f (Branch 12 (Branch 15 Empty Empty) (Branch 28 Empty Empty))
*** Of type ? ?: (Integer,Integer,Tree,Tree,Integer,Tree,Tree)

I'll be happy if you help me to get rid of this error..
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20120311/ad8267ff/attachment-0001.htm>

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

Message: 7
Date: Sun, 11 Mar 2012 19:26:02 +0000
From: Ozgur Akgun <[email protected]>
Subject: Re: [Haskell-beginners] A "show" error
To: bahad?r altan <[email protected]>
Cc: "[email protected]" <[email protected]>
Message-ID:
        <calzazpccbc1sh238ujtyy28a65vwpzp1ikwwxhvyu7fj3rk...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi again,

What interpreter do you use? With ghci, I don't get any errors.

*Main> f (Branch 12 (Branch 15 Empty Empty) (Branch 28 Empty Empty))
(12,15,Empty,Empty,28,Empty,Empty)

On 11 March 2012 19:10, bahad?r altan <[email protected]> wrote:

> Hi,
> I'm trying to process on a tree with this function :
>
> f (Branch x (Branch y y1 y2) (Branch z z1 z2)) = (x,y,y1,y2,z,z1,z2)
>
> and my tree declaration is this :
>
> data Tree = Empty | Branch Integer Tree Tree deriving (Show)
>
> And I'm getting this error :
>
> Main> f (Branch 12 (Branch 15 Empty Empty) (Branch 28 Empty Empty))
> ERROR - Cannot find "show" function for:
> *** Expression : f (Branch 12 (Branch 15 Empty Empty) (Branch 28 Empty
> Empty))
> *** Of type    : (Integer,Integer,Tree,Tree,Integer,Tree,Tree)
>
> I'll be happy if you help me to get rid of this error..
>

-- 
Ozgur Akgun
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20120311/9432433f/attachment.htm>

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

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


End of Beginners Digest, Vol 45, Issue 15
*****************************************

Reply via email to