Hi all , the dependent types are “as” type classes in haskell? , is one
form to put restrictions to the arguments in a function , more o less is
as I
understand ,and sorry for my english…
Here is the issue I see:
Say that obj.toString calls obj2.toString in its body:
obj.toString () {
… obj2.toString() …
}
In order for obj2 to use obj.toStringFormatter, obj2.toString needs to be
modified.This can have a rippling effect as obj2 may call obj3 and obj3 may
…
Also, the effect resulted from calling obj.setToStringFormatter can be
surprising to the next call to obj.toString.On Saturday, December 6, 2014 8:22:36 PM UTC-5, Raoul Duke wrote:
obj.setToStringFormatter( new FooToStringFormatter( “%MM%DD%HH” ) );
in Java, one could use Another Layer of Indirection. toString() is
’hard coded’ per class. But you could have it check for an
instance-level Formatter and then use that if it isn’t null, otherwise
use the ‘hard coded’ version.
Say we have the following pseudo code:
obj = new Foo(…) // Foo is some class
println (obj.toString()); // use one format for floats
println (obj.toString()); // use a different format for floats
What I asked is how to add some code between the two
print statements so that the second one behaves differently
from the first one.On Friday, December 5, 2014 5:36:44 PM UTC-5, Raoul Duke wrote:
in Java, one could use Another Layer of Indirection. toString() is
‘hard coded’ per class. But you could have it check for an
instance-level Formatter and then use that if it isn’t null, otherwise
use the ‘hard coded’ version.
But the philosophy is similar between them , or I did not understand
anything…El miércoles, 3 de diciembre de 2014 22:48:07 UTC+1, Raoul Duke escribió:
Hi all , the dependent types are “as” type classes in haskell?
i think the answer is, “no”.
There are plenty on-line articles on this or similar issues. For instance:
http://www.joachim-breitner.de/blog/398-Making_dictionary_passing_explicit_in_Haskell
The implementation of templates in ATS is rather similar to (but more
complicated than)
Stephan Kae’s implementation of type classes. See:
I think that templates in ATS is less "mathematical’ but a great deal more
flexible when
compared to type classes in Haskell. I will try to write more on this.
The following example demonstrates a way to print out lists of floats in
different formats:
Here is the output if the example is tested:
0, 0, 0
0.1, 0.2, 0.3
0.11, 0.22, 0.33
0.111, 0.222, 0.333
0.1111, 0.2222, 0.3333
0.11111, 0.22222, 0.33333
0.111111, 0.222222, 0.333333On Friday, December 5, 2014 8:52:54 AM UTC-5, Artyom Shalkhakov wrote:
On Friday, December 5, 2014 1:32:00 PM UTC+6, gmhwxi wrote:
The feature in ATS that is closest to type classes is templates.
Let me ask a question that I think can really help understand the
differences
between type classes in Haskell and templates in ATS.Say you define some kind of datatype in Haskell:
data abc = …
Suppose that abc is showable. Then you can call ‘show’ on values of the
type
abc. This is all very convenient. Say, a value x of the type abc contains
a floating
pointer member. Then show(x) prints this floating point number using some
format
(e.g., 6 decimals after the point). Suppose I do not like this format; I
want a different
one (e.g., 2 decimals after the point). How should it done in Haskell?What’s the anwer here? Just wondering.
Off the top of my head:
- resort to explicit dictionary passing
- create a newtype wrapper for floating points, and implement Show for it
manually (downside: this might require a lot of rewriting to accomodate the
new type)I don’t use Haskell so I really have no idea how such an issue is handled.
On Wednesday, December 3, 2014 5:31:29 PM UTC-5, SergioBG BG wrote:
But the philosophy is similar between them , or I did not understand
anything…El miércoles, 3 de diciembre de 2014 22:48:07 UTC+1, Raoul Duke escribió:
Hi all , the dependent types are “as” type classes in haskell?
i think the answer is, “no”.
As I think about this, I wonder if type classes would open Pandora’s box, like should impurity be constrained to an IO monad? Should there be syntactic sugar for monads, arrows, etc. I think the answer for me would be to allow impurity, add sugar, add generation where obvious . That would fit best with what I perceive the design intent to be.
But would there be any value in types classes for different types of numbers? This would encroach on dependent types. Perhaps it would be better to allow type classes to use dependent types to define functions of a class and keep the class hierarchy simpler and for functor, monad, monoid, etc. hm, not sure. Once you go down this path there is temptation for purity of concepts.
The feature in ATS that is closest to type classes is templates.
Let me ask a question that I think can really help understand the
differences
between type classes in Haskell and templates in ATS.Say you define some kind of datatype in Haskell:
data abc = …
Suppose that abc is showable. Then you can call ‘show’ on values of the
type
abc. This is all very convenient. Say, a value x of the type abc contains
a floating
pointer member. Then show(x) prints this floating point number using some
format
(e.g., 6 decimals after the point). Suppose I do not like this format; I
want a different
one (e.g., 2 decimals after the point). How should it done in Haskell?
What’s the anwer here? Just wondering.
Off the top of my head:
- resort to explicit dictionary passing
- create a newtype wrapper for floating points, and implement Show for it
manually (downside: this might require a lot of rewriting to accomodate the
new type)
I don’t use Haskell so I really have no idea how such an issue is handled.> On Wednesday, December 3, 2014 5:31:29 PM UTC-5, SergioBG BG wrote:
But the philosophy is similar between them , or I did not understand
anything…El miércoles, 3 de diciembre de 2014 22:48:07 UTC+1, Raoul Duke escribió:
Hi all , the dependent types are “as” type classes in haskell?
i think the answer is, “no”.
Hi all , the dependent types are “as” type classes in haskell?
i think the answer is, “no”.
i think they not related.
type classes: compile time dynamic dispatch.
http://book.realworldhaskell.org/read/using-typeclasses.html
dependent types: narrower, more refined, types than usual. like, most
languages can say “int”, but dependent types can say “int >= 0”.
http://bluishcoder.co.nz/2010/09/01/dependent-types-in-ats.html
but i don’t really grok these things fully.
sure, all fine points.
I see type classes as a form of meta-programming.
I could imagine some sort of meta-programming plug-in for ATS that allows
you to use type classes. Too many ideas, too little time :(On Tuesday, December 29, 2015 at 4:33:01 PM UTC-5, Mike Jones wrote:
As I think about this, I wonder if type classes would open Pandora’s box,
like should impurity be constrained to an IO monad? Should there be
syntactic sugar for monads, arrows, etc. I think the answer for me would be
to allow impurity, add sugar, add generation where obvious . That would fit
best with what I perceive the design intent to be.But would there be any value in types classes for different types of
numbers? This would encroach on dependent types. Perhaps it would be better
to allow type classes to use dependent types to define functions of a class
and keep the class hierarchy simpler and for functor, monad, monoid, etc.
hm, not sure. Once you go down this path there is temptation for purity of
concepts.
Dependent types , sorry…El miércoles, 3 de diciembre de 2014 22:41:55 UTC+1, SergioBG BG escribió:
Hi all , the dependent types are “as” type classes in haskell? , is one
form to put restrictions to the arguments in a function , more o less is
as I
understand ,and sorry for my english…
Yes, I understand more or less the differences between the two , but I need more time.El viernes, 5 de diciembre de 2014 08:32:00 UTC+1, gmhwxi escribió:
The feature in ATS that is closest to type classes is templates.
Let me ask a question that I think can really help understand the
differences
between type classes in Haskell and templates in ATS.Say you define some kind of datatype in Haskell:
data abc = …
Suppose that abc is showable. Then you can call ‘show’ on values of the
type
abc. This is all very convenient. Say, a value x of the type abc contains
a floating
pointer member. Then show(x) prints this floating point number using some
format
(e.g., 6 decimals after the point). Suppose I do not like this format; I
want a different
one (e.g., 2 decimals after the point). How should it done in Haskell?On Wednesday, December 3, 2014 5:31:29 PM UTC-5, SergioBG BG wrote:
But the philosophy is similar between them , or I did not understand
anything…El miércoles, 3 de diciembre de 2014 22:48:07 UTC+1, Raoul Duke escribió:
Hi all , the dependent types are “as” type classes in haskell?
i think the answer is, “no”.
I find type classes conceptually clear, because they capture a concept in code. If you constrain a type passed to a function to one or more classes, the names of the classes make clear the intent of the function, and errors are clear about any violation. I see them much like dependent types, a clearly described constraint. If the compiler can synthesize the typical ones like show, ord, etc, you save coding time. I think they would be nicer than specific implementations of templates and would make monads and other catagories cleaner.
Is there any reason not to extend ATS with them?
obj.setToStringFormatter( new FooToStringFormatter( “%MM%DD%HH” ) );
I understand time limitations. It may take a team at some point. That is hard to come by without a large user base. That requires time as well.
Any plans for ICFP? If so, perhaps start a topic on that.
The feature in ATS that is closest to type classes is templates.
Let me ask a question that I think can really help understand the
differences
between type classes in Haskell and templates in ATS.
Say you define some kind of datatype in Haskell:
data abc = …
Suppose that abc is showable. Then you can call ‘show’ on values of the type
abc. This is all very convenient. Say, a value x of the type abc contains a
floating
pointer member. Then show(x) prints this floating point number using some
format
(e.g., 6 decimals after the point). Suppose I do not like this format; I
want a different
one (e.g., 2 decimals after the point). How should it done in Haskell?On Wednesday, December 3, 2014 5:31:29 PM UTC-5, SergioBG BG wrote:
But the philosophy is similar between them , or I did not understand
anything…El miércoles, 3 de diciembre de 2014 22:48:07 UTC+1, Raoul Duke escribió:
Hi all , the dependent types are “as” type classes in haskell?
i think the answer is, “no”.