There was a post pointing to the beautiful more than 30 years old 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 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.

mdrslmr boosted

A new approach has allowed first-ever observation of quantum interference between dissimilar particles.
Scientists @brookhavenlab@twitter were able to actually see inside nuclei.

bit.ly/3XKQUZO

#science #fediscience #physics #quantummechanics #particlephysics #scicomm

It is probably a bad idea in ,
but still surprising: 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
mechanism I know.
m.youtube.com/watch?v=qIXpTIVF

In my spare time I learned a bit about and implemented an algorithm concerning multiplet combination, used in high energy .
github.com/mdrslmr/Multiplet-C
It is a bit in between the fields of , and .

Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.