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.  Tree-like Structure with unique elements on      each level (martin)
   2. Re:  Tree-like Structure with unique elements on each level
      (Imants Cekusins)
   3.  Implementing instance of '^' operator (pmcil...@gmail.com)


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

Message: 1
Date: Sat, 2 Jan 2016 20:53:24 +0100
From: martin <martin.drautzb...@web.de>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: [Haskell-beginners] Tree-like Structure with unique elements
        on      each level
Message-ID: <56882ab4.2090...@web.de>
Content-Type: text/plain; charset=utf-8

Hello all,

I recently modeled a tree like this:

data Predicate a = Any | Pred (S.Set a)
data Product a = Pany | Prod (S.Set(Predicate a, S.Set(Product a)))

What I wanted to achieve was to have each element only once on each level. 
Hence the Sets. But this structure does not
achieve this. I can easily duplicate elements on a level as long as their 
subordinates are different, so I might as well
give up working with sets.

Is there a way to construct a tree where each element can occur only once on 
each level?


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

Message: 2
Date: Sat, 2 Jan 2016 22:12:57 +0100
From: Imants Cekusins <ima...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Tree-like Structure with unique
        elements on each level
Message-ID:
        <CAP1qinagm=rsfzhr9w1v37b_m6utukqt2jjk52lyjoymhcj...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

> data Predicate a = Any | Pred (S.Set a)
data Product a = Pany | Prod (S.Set(Predicate a, S.Set(Product a)))

Does this fit:

data Predicate a = Any | Pred  a
data Product a = Pred' (Predicate a) |  Prod (Product a)

?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160102/e0c65895/attachment-0001.html>

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

Message: 3
Date: Sat, 2 Jan 2016 22:55:41 -0800
From: <pmcil...@gmail.com>
To: "beginners@haskell.org" <beginners@haskell.org>
Subject: [Haskell-beginners] Implementing instance of '^' operator
Message-ID: <5688c5ec.e93e420a.22e11.5...@mx.google.com>
Content-Type: text/plain; charset="utf-8"


As a ?hello world? example for type definitions, I like to define a numeric 
type that can handle the mod p multiplicative group, where p is prime. This 
requires:
? Implementing interface functions
? Defining non-trivial implementations, where constructor must be private, etc.
? Invoking an abstract superclass concrete instance method from within the 
subclass method definition
The latter appears not to be possible in Haskell. Is this true?
Here?s the basic code, but I punted on x^n. It looks like I?d have to paste in 
the entire original definition of ?^?.
data Modp a = Modp a a deriving (Eq, Show)

mkModp p n | isPrime p = Modp p (n `mod` p)
           | otherwise = error $ show p ++ " is not a prime"

instance Integral a => Num (Modp a) where
         (Modp q n) + (Modp p m) | p==q = Modp p $ (n+m) `mod` p
                                 | otherwise = error $ "unequal moduli"
         (Modp p n) * (Modp q m) | p==q = Modp p $ (n*m) `mod` p
                                 | otherwise = error $ "unequal moduli"
         negate (Modp p n) = Modp p (p-n)
         -- can't reuse base because ^ is impl. directly in prelude
{-       (Modp p x) ^ n | n <= p  = (Modp p x) `baseExp` n
                        | n1 == 0 = (Modp p x)
                        | n > p   =  x ^ n1
             where baseExp = ^ in Num
                   n1      = n `mod` p
-}
instance Integral a => Fractional (Modp a) where
         recip (Modp p n) = (Modp p n)^(p-2)


isPrime p = True        -- stub
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160102/dd8c3229/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 91, Issue 3
****************************************

Reply via email to