On Mon, Apr 16, 2012 at 08:16:42PM +0200, Waldek Hebisch wrote:
> Serge D. Mechveliani wrote:
> > 
> > I am sorry, may I ask, again, a question about categories and standard 
> > constructors?
> > This time it is more concrete.
> > Concerning my request on adding categories to standard constructors
> > Waldek wrote 
> > 
> > > Why do you need Integer (etc.) to have ParseCategory?  You can have:
> > >
> > > ParseCategory(T : SetCategory) : Category ==  SetCategory with
> > >   parseElem : String -> Product(T, String)
> > > [..]
> > >
> > > and then implement packages of that category.
> > 
> > 2. Here is a concrete and small contrived example/question presented by
> >    an Haskell program.
> > 
> 
> [..]
> Now, I admit that if you insist on your interface, that is
> all you have is just a type (which is build from limited
> set of constructors but allows arbitrary composition), then
> Spad does not offer solution to you problem (as opposed
> to workarounds).

Let it be all compositions of  Integer, Product, List.
If `show' works for this, then I can program all the rest. 

> OTOH, when we look at your real problem (that is of creating
> Haskell interface), than I feel that there is quite
> satisfactory solution.  Namely, you start from a string
> describing type.  Parsing this string you create type
> and a package containg appropriate function(s): a
> function to parse strings to the type and a function to
> unparse elements of the type to stings.  Concretely, you have:
> 
> UnparserCategory(T : Type) : Category == with (show : T -> Sting)
> 
> SparseUnivariatePolynomialUnparser(R : Ring, UR : UnparserCategory(R)) : _
>   UnparserCategory(SparseUnivariatePolynomial(R))
>  == add
>     show(x) ==
>        x = 0 => "([], [])"
>        dl := List(NonNegativeInteger) :=  reverse(map(degree, monomials(p)))
>        cl := List(String) := reverse(map(show$UR, coefficients(p)))
>        s1 : String := toString(first(dl))
>        s2 := frist(cl)
>        for i in rest(dl) for c in cl repeat
>            s1 := concat(toString(i), concat(", "), s1)
>            s2 := concat(c, concat(", "), s2)
>        concat(["([", s1, "], [", s2, "])"])
> 
> Note: I assumed that there is a function to convert integers to
> strings.  ATM one has to do something like
> 
>    toString(i : Integer) : String == FORMAT(nil, "~d", i)$Lisp
> 
> or
> 
>    toString(i : Integer) : String == unparse(i::InputForm)$InputForm
> 
> 
> Case of Product is easier:
> 
> ProductUnparser(A : SetCategory, B : SetCategory,
>                 UA : UnparserCategory(A), UB : UnparserCategory(B)) _
>                : UnparserCategory(Product(A, B))
>  == add
> 
>    show(x) ==
>        concat("[", concat(show(first(x))$UA, concat(", ", _
>           concat(show(second(x)$UB, "]")))))

If you also similarly define `show' for List,  will this work for  

  show ([ [construct(1,2), construct(3,4)],
          [construct(5,6), construct(7,8)] ]
                                       :: List List Product(Int, Int))
?
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.

Reply via email to