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?
=== haskell ===
--data type Tree is
-- a Leaf containing a single item (of type a)
-- 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
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.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.