Martin, Ralf, et al.; I think this is a very good exercise for both the SPAD compiler and for the application of category theory in Axiom and it's derivatives.
The following code "almost compiles" in FriCAS and the way it fails illustrates some problems in both SPAD and Aldor: First 'Category' is not a known type in FriCAS (It is a type in OpenAxiom! and in Aldor). So instead of 'Category' I wrote 'Type'. But the output of the command ')show MonadCat2' already suggests that something is going wrong. If MonadCat2 is compiled with Aldor using Category then things look better but we still run into problems later when trying to instantiate this category. There always has been a problem at the top of the type hierachy in Axiom. Various flavors have tried to solve this - all unsuccessfully, I think. Second, we are trying to pass the functor M as a parameter. Specifying this is a currently very awkward in both SPAD and Aldor. What Ralph wrote involves passing a function which returns domain. In Axiom and it's derivatives this is not the same thing as a domain constructor (= functor). This is a rather deep issue in the fundamental design of SPAD and Aldor where types are supposed to be static and I am not sure if it was ever fully resolved. Maybe OpenAxiom has made some progress here as well? -- )abbrev category MONADC MonadCat2 MonadCat2(C: Type, A : C, M: C -> C): Category == with unit: A -> M A mult: (M A, M A) -> M A -- )show MonadCat2 MonadCat2(C: Type,A: t#1,M: (t#1 -> t#1)) is a category constructor Abbreviation for MonadCat2 is MONADC This constructor is exposed in this frame. ------------------------------- Operations -------------------------------- mult : (M(A),M(A)) -> M(A) unit : A -> M(A) In principle would could instantiate MonadCat2 as follows: MonadCat2(SetCategory, Integer, (X:SetCategory):SetCategory+->List X) but we can not write this in FriCAS, so try to use Type instead. -- )abbrev domain MONDIL MonadIntegerList MonadIntegerList(): MonadCat2(Type, Integer, (X:Type):Type+->List X) == add unit(x:Integer):List Integer == list(x) mult(x:List Integer,y:List Integer):List Integer == concat(x,y) -- Notice here that I explicitly attempted to construct a function which returns a domain: (X:SetCategory):SetCategory +-> List X 'List' is the domain constructor (functor), but both FriCAS and Aldor complain in various ways. Maybe someone else can find a variant that does compile? Regards, Bill Page. > Martin Baker wrote: >> What I would really like to work out is why things like this Haskell >> code: >> >> class Monad m where >> unit :: a -> m a >> mult :: m (m a) -> m a >> >> which are so powerful seem to be hard to do in SPAD related languages? On Tue, Nov 8, 2011 at 8:36 AM, Ralf Hemmecke <[email protected]> wrote: > > Does the above express something similar to > > #include "aldor" > Monad(C: Category, A: C, M: C -> C): Category == with { > unit: A -> M A; > mult: M M A -> M A; > } > > ? That's compiling in Aldor, but as such is pretty useless. You would have > to give some implementation of that category. > > But what I've written above, is actually not really, what I imagine you > want. In fact, in the end, you might want something like this: > > Monad(C: Category, 1: C -> C, M: C -> C): Category == with { > unit: 1 -> M; > mult: (M, M) -> M; > } > > (which doesn't compile in aldor). > >> It would help if I understood what it is about the above Haskell >> class that makes it so difficult to represent in SPAD. Is it somthing >> about allowing partial types to be combined to form a complete type? >> I just can't work it out. > > The Haskell class alone doesn't help much. What do you want to achieve? You > might want to write a Haskell program (with monads) and explain what it does > and only then we can try to represent it in SPAD. > > Ralf > -- You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/fricas-devel?hl=en.
