On Mon, Apr 16, 2012 at 08:16:42PM +0200, Waldek Hebisch wrote:
> Serge D. Mechveliani wrote:
[..]
> > 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.
[..]
> 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, "]")))))
I am trying to understand and to simplyfy the example:
------------------------------------------------------------------------
)abbrev category UNPARSE UnparserCategory
UnparserCategory(T : Type) : Category == with (show : T -> String)
)abbrev package LUNPARS ListUnparser
ListUnparser(T : Type, UT : UnparserCategory(T)) : _
UnparserCategory(List(T))
== add
show(xs : List T) : String ==
empty? xs => "[]"
x := first xs
xs := rest xs
str := concat("[", show(x) $UT)
while not empty?(xs) repeat
x := first xs
xs := rest xs
str := concat[str, ",", show(x) $UT]
concat(str, "]")
------------------------------------------------------------------------
I defined ListUnparser after your sample of
SparseUnivariatePolynomialUnparser,
without much understanding, and in order to see how this `show' works
for all compositions of Integer and List:
List INT, List List INT, etc.
1. Is this ListUnparser what you meant?
2. Must it be `)abbrev package' or `)abbrev domain' ?
3. If it is what you meant, then how to call `show' for
List INT, List List List INT ?
I am asking this naive questions because hope that your answers will
help me to understand your approach.
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.