1

There's been some conflicting views opinions on SO and elsewhere on whether the JQuery object is a monad or not. My question is, however, if the JQuery like object in d3.js qualifies as a monad, i.e. that it has these properties:

  1. type constructor.
  2. unit function.
  3. binding operation.
Community
  • 1
  • 1
Perry
  • 1,709
  • 1
  • 17
  • 25
  • 1
    I'm not familiar with jQuery or d3.js, but in order for something to be a monad those last two items in that list must satisfy certain laws (it looks like these are not expressed in very specific terms in your second link). Here are the specific laws given in terms of Haskell syntax: http://hackage.haskell.org/package/base-4.7.0.1/docs/Control-Monad.html#t:Monad (`return` is unit and `>>=` is bind). – David Young Dec 23 '14 at 01:36

2 Answers2

1

There's no evidence that the object in d3.js implements the necessary operations (bind,join,return etc) or that those operations satisfy the monad laws. Typically, such objects have lots of backdoors and holes in the API that break any such laws. So the answer is almost certainly no.

Don Stewart
  • 137,316
  • 36
  • 365
  • 468
0

I'm not sure what you mean by "the D3 object", but things that use closures like the layouts are somewhat monadic (although I wouldn't call the monads). They do encapsulate state that you can modify, and you can get something out of the monad by running them on some data.

Monads are more general than that. In particular, they determine how data can be passed from one component to another, which (D3) closures don't do at all. See also this question.

The same things mentioned in the first answer to the question you've linked to also apply here -- you'd have to show that the API is monadic.

Community
  • 1
  • 1
Lars Kotthoff
  • 107,425
  • 16
  • 204
  • 204
  • I actually wanted to write "Is d3 a monad?", though that was too short for a title. However, I was lead to believe that d3 is an object, seing that when you type in "d3" in the console, you get `Object {version: "3.5.2", ascending: function, descending: function, min: function, max: function…}` – Perry Dec 23 '14 at 18:10