On Mon, Apr 16, 2012 at 09:19:44AM +0200, Ralf Hemmecke wrote:
> Hi Sergei,
>
> Concerning
>
>>> 2. Here is a concrete and small contrived example/question presented by
>>> an Haskell program.
>
> of
> http://groups.google.com/group/fricas-devel/browse_thread/thread/e2ed201491e8d2ab?hl=en
>
> .
>
> To be honest, I don't quite understand your problem.
>
> Do you just want a way to print an object of a certain domain? In this
> case implementing CoercibleTo(OutputForm) is the way to go.
1.
In the needed interface, Axiom
(my function parseEvaluateShow : String -> String in Spad)
must return a String to the pipe to DoCon (Haskell)
(DoCon knows ab initio the domain D of the result, and it converts this
string to D).
For example, Axiom returns "([4,3], [-2, 1])",
and DoCon knows that this is for Integer[x], and it converts this
string to the internal data (UPol "x" [(-2,4), (1,3)])
-- which represents -2*x^4 + x^3.
parseEvaluateShow is defined to return here "([4,3], [-2, 1])"
rather than "-2*x^4 + x^3", because the former is more close both to
the DoCon internal data and to the Spad internal data.
How precisely this `show' maps -- I have demonstrated in a small Haskell
code in a recent letter.
And Spad data --> String must be as fast as possible.
So, data :: OutputForm --> String
and data :: InputForm --unparse -> String
must be avoided here. Right?
So, I need to directly print the computed internal data to String
rather than to OutputForm.
Let it be CoercibleTo(String) -- if such has sense.
And I call `show' this `coerce'.
So, I need to define show : T -> String
(or maybe, coerce : T -> String)
recursively for the constructors of Integer, Product, List, Fraction, UP
(so far, restict to this small set).
For example,
coerce : List Product(Fraction Int, UP(x, Fraction Int)) -> String
must work, and it must work for any sensible compositon of these
constructions.
2. This is also an example on programming in Spad
-------------------------------------------------
How to program in Spad in a "categorial" style?
Take this `show : T -> String' as an user operation, and program its
instances by new for the above 5 constructors, without replacing `show'
with any existing library operations.
I can do this in Haskell, the demonstrated code is small.
So: I understand how to program in Haskell.
But I fail to program this in Spad (without defining copies for certain
5 library domain constructors).
So: I do not understand, generally, how to program in Spad.
That is the problem.
The first real problem was of a recursive tree domain.
It is done by rather a complex code -- but let it be.
Now, I face the second problem.
Probably, I am missing something about packages/domains.
> If you like translate it into a category Show
>
> Show: Category == CoercibleTo OutputForm
>
> In your Haskell example you had to implement the function show for each
> class.
I implemented the instances of `show' for each _domain constructor_ from
the set of {Integer, (,) [], Fraction, UPol}.
> I guess, you have already seen the following implementations.
>
> https://github.com/hemmecke/fricas-svn/blob/master/src/algebra/product.spad.pamphlet#L57
> https://github.com/hemmecke/fricas-svn/blob/master/src/algebra/fraction.spad.pamphlet#L66
> https://github.com/hemmecke/fricas-svn/blob/master/src/algebra/list.spad.pamphlet#L99
>
> That is in my eyes basically that what you want to achieve with your
> Haskell example.
Sorry, I look into fraction.spad.pamphlet, list.spad.pamphlet, and
cannot find its relation to my question.
1) I have explained what `show' must do,
2) you observe the corresponding Haskell code above, it is small and
clear.
Can anybody demonstrate the correspoding Spad code for this problem?
Regards,
-----------------
Serge Mechveliani
[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.