On Mon, Apr 16, 2012 at 04:45:56PM +0400, Serge D. Mechveliani wrote:
> On Mon, Apr 16, 2012 at 09:03:49AM +0200, Ralf Hemmecke wrote:
> >> 1. I know what is "a domain of that category",
> >> but what does this mean: "a package of that category" ?
> >
> > A category (or in other words, an interface) is (basically) just a list
> > of exports of the form
> >
> > foo: A -> B
> >
> > A domain or package is an implementation of this interface.
> > The difference between package and domain is: in the exports of a domain
> > appears % in the exports of a package it doesn't. But, I'm sure you know
> > this already.
>
> Spad understands d : D, for a domain D.
> But if D is a package, it, probably would not.
> Respectively, if d : D, D : Ring, then Spad understands what is d*d,
> without the user program specifying the origin of "*".
> And with a package, the user program needs also to define from where the
> function f is taken which is applied to d.
> Right?
>
> So where exactly is your problem with the above?
>
> The problem is: how to follow the advice?
> 1) Define
> category Show : Category with show : % -> String
>
> All right.
>
> 2) "And define packages of that category".
>
> What packages to define in order to make `show' to print as folows?
>
> show ( [(1,-1),(2,-2)] :: List Product(INT,INT) ) -->
> "[(1,-1),(2,-2)]"
>
> show ( [ [(1,-1),(2,-2)], [(3,4)] ] :: List List Product(INT,INT) )
> -->
> "[[(1,-1),(2,-2)],[(3,4)]]",
> and so on, for compositions?
Earlier I demonstrated two pieces of Haskell code to formulate the
problem.
But may be, people do not want to look into the Haskell code.
ASo I re-formulate it in Spad --
only assuming that it allows adding category instances to the standard
library domain constructors.
So, the code is contrived:
------------------------------------------------------------------------
category Show() : Category == SetCategory with show : % -> String
--------------
domain Integer() : Export == Implementation where
-- add Show to the domain of Integer
Export == Join(Integer export, Show)
Implementation == Integer add
show n == string n
--------------
domain Product(S : SetCategory, T : SetCategory) :
Export == Implementation where
Export == Product(S,T) export
if S has Show and T has Show then Show
-- add Show to the domain of Product
Implementation == Product(S, T) add
if S has Show and T has Show then Show
-- add Show to the domain of Product
Implementation == Product(S, T) add
if S has Show and T has Show then
show(p : %) : String ==
concat[ "(", show (first p), ",", show (second p), ")" ]
--------------
domain List(T : Type) : Export == Implementation where
Export == Product export
if T has Show then Show -- add to the List(T) domain
Implementation == List(T) add
if T has Show then
show(xs : %) : String == -- print xs to string
empty? xs => "[]"
x := first xs
xs := rest xs
str := concat("[", show x)
while not empty?(xs) repeat
x := first xs
xs := rest xs
str := concat[str, ",", show x]
concat(str, "]")
------------------------------------------------------------------------
-- 29 non-empty lines.
Example of usage:
show ([ [construct(1,2), construct(3,4)],
[construct(5,6), construct(7,8)] ]
:: List List Product(Int, Int))
->
"[[(1,2),(3,4)],[(5,6),(7,8)]]"
Now, as Spad does not allow adding category instances to the standard
library domain constructors: how to improve this program for Spad ?
What precisely packages to write?
I do not understand what can be an alternative approach to the Spad-like
design displayed above.
Thanks,
------
Sergei
[email protected]
--
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.