in reply to Haskell vs Perl 6 (was Re: Capturing parenthesis and grouping square brackets)
in thread Capturing parenthesis and grouping square brackets
Would you (or someone else) be willing to explain the Haskell code to me or P5ers who don't know Haskell?
With license:
=== haskell === --data type Tree is --either -- a Leaf containing a single item (of type a) -- or -- a Node containing two subtrees (that can have leaves of type a) data Tree a = Leaf a | Node (Tree a) (Tree a) -- and it inherits 'methods' / 'roles' from types Show and Eq, deriving (Show, Eq) -- Fringe is a function that extracts a list of type a from a tree con +taining type a fringe :: Tree a -> [a] -- If its argument is of type leaf -- it returns a single element list containing the element held in the + leaf fringe (Leaf x) = [x] -- If its argument is a Node -- it returns the list returned by the left subtree -- concatenated to the list returned by the right subtree fringe (Node n1 n2) = fringe n1 ++ fringe n2 -- sameFringe takes two Trees as its arguments -- and uses the == method inherited/included from the Eq role -- to compare the lists returned from the two trees for equality -- returning true if they are the same. sameFringe :: (Eq a) => Tree a -> Tree a -> Bool sameFringe t1 t2 = fringe t1 == fringe t2
Personally, I find the Perl6 far easier to read. I'd be very happy to use Perl6 if it had threading and ran at perl5 speed.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Haskell vs Perl 6 (was Re: Capturing parenthesis and grouping square brackets)
by Jenda (Abbot) on Jul 03, 2013 at 13:48 UTC | |
by BrowserUk (Patriarch) on Jul 03, 2013 at 14:58 UTC | |
by raiph (Deacon) on Jul 04, 2013 at 16:08 UTC | |
by raiph (Deacon) on Jul 04, 2013 at 15:27 UTC | |
by Jenda (Abbot) on Jul 04, 2013 at 15:46 UTC | |
by raiph (Deacon) on Jul 04, 2013 at 16:22 UTC |