There was a post pointing to the beautiful more than 30 years old #functionalprogramming paper "Why Functional Programming Matters" John Hughes. I could not find the post again to reply,
The paper gives a definition of "foldtree" on page 7:
"
foldtree f g a (Node label subtrees) =
f label (foldtree f g a subtrees)
foldtree f g a (Cons subtree rest) =
g (foldtree f g a subtree) (foldtree f g a rest)
foldtree f g a Nil = a
"
I wonder what the type of "foldtree" could be. Since the last argument
is "treeof ∗" in the first declaration but "(listof (treeof ∗)" in the second.
In #haskell I would implement it as:
data Tree a = Node a [Tree a]
foldtree :: (a -> b -> b) -> (b -> b -> b) -> b -> Tree a -> b
foldtree f g a (Node x []) = f x a
foldtree f g a (Node x (t:ts)) =
g (foldtree f g a t) (foldtree f g a (Node x ts))
But probably I'm miss something here, since it takes only two declarations.
It is probably a bad idea in #Haskell,
but still surprising: #ghc does not
complain about using "do" to define (>>=) itself.
It seams to cause and endless loop.
newtype BadIdea a = B a
deriving Show
instance Functor BadIdea where
fmap f (B a) = B (f a)
instance Applicative BadIdea where
pure x = B x
(B f) <*> B x = B (f x)
instance Monad BadIdea where
return x = B x
ma >>= f = do
a <- ma
f a
-- instead of
-- (B a) >>= f = f a
main = print
(B 5 >>= (\x -> B (2*x)))
Not new but still the best 2 minutes , well, sketch of the
Brout-Englert-Higgs
#Higgs mechanism I know. #Particles #CERN #Physics
https://m.youtube.com/watch?v=qIXpTIVFF7I
In my spare time I learned a bit about #Haskell and implemented an algorithm concerning multiplet combination, used in high energy #physics .
https://github.com/mdrslmr/Multiplet-Combining
It is a bit in between the fields of #Haskell #functionalprogramming , #physics and #grouptheory .
Interested in physics, science, software e.g. haskell, ...