r/functionalprogramming • • Feb 28 '23

Question Is JSX a hidden monad bind?

Say we have this example

function Component() {
   return <Layout><Page /></Layout>
}

And lets assume this is compiled to

function Component() {
   return jsx(Layout, jsx(Page));
}

where type of jsx is (fn, JSX.Element) => JSX.Element. For simplicity ignore that we can have multiple elements in the second argument.

jsx is not in the form of monadic bind (JSX.Element, (fn) => JSX.Element) => JSX.Element. If we ignore the laws, can we say jsx is a special case of the monadic bind function nevertheless?

15 Upvotes

25 comments sorted by

View all comments

Show parent comment

2

u/ibrahimbensalah Feb 28 '23

Thank you for confirmtion, I based my conclusion solely on intuition, first I though JSX is only a concat operation like array concat, but I am starting to think it could be more.

4

u/EsperSpirit Feb 28 '23

If you're thinking about combining values (e. g. JSX fragments), you might want to look at Semigroup and Monoid.