Group Abstract Group Abstract

Message Boards Message Boards

Implementing Haskell's state monad and do notation in Wolfram

Posted 5 months ago

Attachments:
POSTED BY: Eric Parfitt
7 Replies

Mr. Eric Parfitt

I had the pleasure of a quick exchange a few years back on some emails discussing some Mathematica release at the time. I would like to inform you that I am currently working on Monad's Natural Transformation per Mac Lane and Francis Borceux Handbook of Categorical Algebra 2.

I like to experiment with a Haskell evaluator or a related concept in 14.3 which is the current version.

I develop the new language interfaces via the Notations package, and therefore make a programming environment on top of the Wolfram Editor that is more suitable for standard formal systems.

POSTED BY: Dara Shayda

I have some difficulty matching the Haskell Monad's and others to actual math text from Mac Lane or others!? Seems we are not talking about the same concepts.

If possible Mr. Eric Parfitt I like to discuss this matter in more technical details, of course we can create a ticket, we are Enterprise license paying customer + strategic partner. You can pink Mr. Harden or Mr. Fleck for my background with WRI.

I hope I was not imposing

Dara

POSTED BY: Dara Shayda

The following is the Category Theory Definition of Monad, confirmed as such with Mac Lane, and I am failing to see much resemblance to Haskell Monad. However, shock to my core, Monads are the foundation of Expressions and List in Wolfram Mathematica, verbatim my red selections are a part of the Wolfram language and new features in 14.3 has made implementing Monads as programmable structures much easier.

I compared these definitions and structures with Haskell and saw much confusion:

  1. Monad is about Transforming Lists or Sequences into Multiplicative Monoids
  2. And do so in a cookie-cutter manner that works for most? categories
  3. This causes a structure separation for any function: a) the structure that involves maintaining the data shared amongst all functions via Lists, b) the structure is which actually the body of the function and structure is called Natural Transformation, actually two, see this ref: https://ncatlab.org/nlab/show/monad#Idea

I see faint traces of 3.a in Haskell, in a vague manner that requires much English verbiage to explain.

In Wolfram language 1,3.a are part of the core language!

Q: Why do we need to study programmable Monads in the Wolfram language? A: Because we need to extend/reimplement some Multiplicative monoids already in place in the language. Or turn programming structures in the language that are not in monoidal forms e.g. we have developed code to turn DiracDelta[ ] function into a pre-fix operator as a product.

POSTED BY: Dara Shayda

Dear Dara: I can see in figure 4.1 and its explanation above the signature of flatmap, i.e., map a function and flatten exactly once. I think of flatmap as the central abstraction of Haskell monads. Also compare to SelectMany in C# / Linq, which is exactly flatmap, bringing C# as close to Haskell as it can come.

POSTED BY: Brian Beckman

Thank you Mr. Beckman

Indeed that is the case in the mentioned diagram + Flatten at Wolfram. I have a larger and more detailed document with actual Wolfram code adaptations of the original literature by two gurus of Category theory and Monadic theories Mac Lane and Francis Borceux.

However, I CANNOT SEE much of the Monad theory in Haskell. Watched tons of videos on Haskell monad this and that, and I was dazed and missed the point. Yet here in Wolfram Platform I know all the functions for the Monad implemented by heart!

Just to have a function that Flattens a list does not warrant a Monad structure!? So you can have a theory or programming language that does all the list operations the Monad includes and yet it has nothing to do with the aim and purpose and implementation of a Monad:

https://reference.wolfram.com/language/ref/NonThreadable.html

This is a new feature in 14.1, That is a component of the core of my Monad categorization in Mathematica. See the 2nd Red text Box highlight in the first page scanned page in my earlier post. Threading needs to be turned on or off at crucial parts of the evaluations for the Monadic expressions to work per mathematics of the theory.

Regards Dara

POSTED BY: Dara Shayda

Related links:

POSTED BY: Anton Antonov

enter image description here -- you have earned Featured Contributor Badge enter image description here Your exceptional post has been selected for our editorial column Staff Picks http://wolfr.am/StaffPicks and Your Profile is now distinguished by a Featured Contributor Badge and is displayed on the Featured Contributor Board. Thank you!

POSTED BY: EDITORIAL BOARD
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard