This may be a better definition of Monad in Axiom.

Ref: http://en.wikibooks.org/wiki/Haskell/Category_theory

## A monad is an endofunctor

In Axiom a functor is a domain constructor. An endofunctor takes a domain in some category and constructs a domain in that same category.

aldor

--)abbrev category MONADC MonadCat
#pile
#include "axiom"
MonadCat(A : Type, M: Type -> Type): Category == with
if A has SetCategory then SetCategory
fmap: (A->A, %) -> %
unit: A -> %
join: M % -> %
mult: (%, %) -> %

aldor

Compiling FriCAS source code from file
/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/monadcat.as
using AXIOM-XL compiler and options
-O -Fasy -Fao -Flsp -laxiom -Mno-ALDOR_W_WillObsolete -DAxiom -Y $AXIOM/algebra -I $AXIOM/algebra
Use the system command )set compiler args to change these
options.
The )library system command was not called after compilation.

fricas

)show MonadCat

The )show system command is used to display information about types
or partial types. For example, )show Integer will show
information about Integer .

MonadCat is not the name of a known type constructor. If you want
to see information about any operations named MonadCat , issue
)display operations MonadCat

aldor

--)abbrev domain MONADL MonadList
#pile
#include "axiom"
#library lmonadcat "monadcat.ao"
import from lmonadcat
MonadList(A:Type): MonadCat(A,List) == add
Rep == List A
import from Rep
rrep(x:%):Rep == x pretend Rep
--perr(x:Rep):% == x pretend %

fmap(f:A->A,x:%):% == per(map(f,rep x)$ListFunctions2(A,A))
unit(x:A):% == per list(x)
join(x:List %):% == per(concat(map(rrep,x)$ListFunctions2(%,Rep)))
mult(x:%,y:%):% == per concat(rep x,rep y)
if A has SetCategory then
coerce(x:%):OutputForm == rep(x)::OutputForm
((x:%) = (y:%)):Boolean ==
L:List Boolean := map(_=$A,rep x,rep y)$ListFunctions3(A,A,Boolean)
reduce(_and,L,false)$ListFunctions2(Boolean,Boolean)

aldor

Compiling FriCAS source code from file
/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/2630045957127378990-25px003.as
using AXIOM-XL compiler and options
-O -Fasy -Fao -Flsp -laxiom -Mno-ALDOR_W_WillObsolete -DAxiom -Y $AXIOM/algebra -I $AXIOM/algebra
Use the system command )set compiler args to change these
options.
The )library system command was not called after compilation.

fricas

)show MonadList(Integer)

The )show system command is used to display information about types
or partial types. For example, )show Integer will show
information about Integer .

MonadList is not the name of a known type constructor. If you
want to see information about any operations named MonadList ,
issue
)display operations MonadList

Integer is not the name of a known type constructor. If you want
to see information about any operations named Integer , issue
)display operations Integer

fricas

L1 := unit(1)$MonadList(Integer)

There are no library operations named MonadList
Use HyperDoc Browse or issue
)what op MonadList
to learn if there is any operation containing " MonadList " in
its name.

Cannot find a definition or applicable library operation named
MonadList with argument type(s)
Type

Perhaps you should use "@" to indicate the required return type,
or "$" to specify which version of the function you need.

spad

)abbrev domain MAYBE2 Maybe2
Maybe2(R:SetCategory):SetCategory
== add
Rep := Union(R,"failed")
rep(x:%):Rep == x pretend Rep
per(x:Rep):% == x pretend %

spad

Compiling FriCAS source code from file
/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/4607644844684909994-25px006.spad
using old system compiler.
MAYBE2 abbreviates domain Maybe2
------------------------------------------------------------------------
initializing NRLIB MAYBE2 for Maybe2
compiling into NRLIB MAYBE2
compiling local rep : $ -> Rep
MAYBE2;rep is replaced by x
Time: 0 SEC.

compiling local per : Rep -> $
MAYBE2;per is replaced by x
Time: 0 SEC.

(time taken in buildFunctor: 0)

;;; *** |Maybe2| REDEFINED

;;; *** |Maybe2| REDEFINED
Time: 0 SEC.

Warnings:
[1] rep: pretendRep -- should replace by @
[2] per: pretend$ -- should replace by @

Cumulative Statistics for Constructor Maybe2
Time: 0 seconds

finalizing NRLIB MAYBE2
Processing Maybe2 for Browser database:
--->-->Maybe2(): Missing Description
; compiling file "/var/aw/var/LatexWiki/MAYBE2.NRLIB/MAYBE2.lsp" (written 06 OCT 2017 09:49:02 PM):

; /var/aw/var/LatexWiki/MAYBE2.NRLIB/MAYBE2.fasl written
; compilation finished in 0:00:00.015
------------------------------------------------------------------------
Maybe2 is now explicitly exposed in frame initial
Maybe2 will be automatically loaded when needed from
/var/aw/var/LatexWiki/MAYBE2.NRLIB/MAYBE2

spad

)abbrev domain MAYBE2 Maybe2
Maybe2(R:SetCategory):MonadCat(R,Maybe2)
== add
Rep ==> Union(R,"failed")
rep(x:%):Rep == x pretend Rep
per(x:Rep):% == x pretend %

fmap(f:R->R,x:%):% ==
rep(x) case R => per f(rep x)
per "failed"
unit(x:R):% = per x
join(x:Maybe %):% ==
rep(x) case "failed" => per "failed"
rep(rep x) case "failed" => per "failed"
x

spad

Compiling FriCAS source code from file
/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/2461590120764584468-25px007.spad
using old system compiler.
MAYBE2 abbreviates domain Maybe2
------------------------------------------------------------------------
initializing NRLIB MAYBE2 for Maybe2
compiling into NRLIB MAYBE2
cannot produce category object:
(|MonadCat| R |Maybe2|)

>> Apparent user error:
cannot produce category object

fricas

)show Maybe

The )show system command is used to display information about types
or partial types. For example, )show Integer will show
information about Integer .

Maybe is not the name of a known type constructor. If you want to
see information about any operations named Maybe , issue
)display operations Maybe

fricas

x:Maybe(Integer):= unit(-1)

There are no library operations named Maybe
Use HyperDoc Browse or issue
)what op Maybe
to learn if there is any operation containing " Maybe " in its
name.

Cannot find a definition or applicable library operation named Maybe
with argument type(s)
Type

Perhaps you should use "@" to indicate the required return type,
or "$" to specify which version of the function you need.