This should indicate a way to assign a linear type to co-routines. Please
feel free to use
the code to implement other functions.
If a coroutine is assigned a linear type, then calling co_run on the
coroutine also frees it.
This way to manage memory can be much more efficient then using GC.
Also, I suggest to make ‘coroutine’ an abstract type; make ‘event’ an
abstract type, too.
By using viewt@ype as base types for my coroutines functions, I have an
error because x is consumed twice so the compiler error :
… there is no type for the dynamic variable [x]
My question is : how to overcome this ?
thanks a lot
This technique is quite straightforward to achieve expressive FRP.
Knowing that the haskell community is quite large, most of resources
available on the internet does apply to haskell language.
As an intermediate haskell user, I would say that linear type and dependent
type are quite different of all programming habits around, therefore the
amount of efforts to get into linear and dependent thinking is high.
The haskell community has a great thing : The monad Reader
( http://themonadreader.wordpress.com/ ) It is an electronic magazine that
demonstrate the power of underlying architecture of a haskell : monads.
Maybe would be great to have The linear/dependent type Reader to show to
the world the power of ATS
FYI, I just tried your example in ATS2 and also observed the C compiler
problem.
I wasn’t familiar with coroutines, but after looking at them, I wonder if
mutually tail recursive closures, at least in ATS, might have the same
benefits as coroutines (as well as perhaps being easier to read) - aside
from having to put the “yield” in the tail position.
implement print_resource(x) = printf("%d ", @(x))
implement print_resource<event_vt(int)>(x) = let
val l = list_of_event{int} x
in
print_free_list l
end
implement print_resource(x) = printf("%f ", @(double_of_float x))
implement print_resource<event_vt(float)>(x) = let
val l = list_of_event{float} x
in
print_free_list l
end
implement main () = let
val e = event_of_list{int}(list_vt_cons(1, list_vt_cons(2, list_vt_nil())))
in
print_resource e
end
this typecheck but at the C compilation an error occurs :
bug_v_dats.c:238: error: redefinition of ‘print_resource_01812_ats_ptr_type’
bug_v_dats.c:172: error: previous definition of
’print_resource_01812_ats_ptr_type’ was here
if I comment the “implement print_resource<event_vt(float)>(x)” function it
works
As an intermediate haskell user, I would say that linear type and
dependent type are quite different of all programming habits around,
therefore the amount of efforts to get into linear and dependent thinking
is high.
Dependent types are tied to quantification in logic. My own teaching
experience tells me that a majority of programmers have difficulty dealing
with quantifiers.
This is a bit like in Calculus: most people learning calculus cannot
precisely define what continuity really is; this concept involves two
quantifies: forall … exists …;
fewer people could understand uniform continuity: exists … forall …
exists. Actually many mathematicians proved false theorems in 19th century
because they messed up with the concept of uniform continuity (e.g., Dini
theorem is a good example involving this concept)
Linear types are quite different. This concept is tied to our intuition
about objects in the physical world. My own teaching experience indicates
that most programmers have no difficulty using linear types.
The haskell community has a great thing : The monad Reader ( http://themonadreader.wordpress.com/ ) It is an electronic magazine that
demonstrate the power of underlying architecture of a haskell : monads.
I took a glance. Very nice. However, we must not forget the basic
philosophical point:
You can see the physical world through the lens of monad or just see it as
it is (linear types).
Maybe would be great to have The linear/dependent type Reader to show to
the world the power of ATS
I could only do so much. It is up to the users of ATS to show the world the
power of ATS. Of course, I will be happy to contribute.
coroutine (a, b) was defined as: (a) -<lin,cloptr1> b
If you allow a and b to be linear types, then there are two possibilities
for coroutine(a,b)
(a) -<lin,cloptr1> b
(!a) -<lin,cloptr1> b
I think that the latter is a more natural definition.
Questions like this that rise naturally in a linear setting can be really
interesting. However, they have not
be carefully studied yet.