Re: Retry: ITypes and VTypes.

2005-02-04 Thread Autrijus Tang
On Thu, Feb 03, 2005 at 03:59:06PM -0800, Brent 'Dax' Royal-Gordon wrote:
> Autrijus Tang <[EMAIL PROTECTED]> wrote:
> > However, I'd still like to know whether my understanding on punning
> > (same class 'Array' used as both Implementation Type and Value Type)
> > and the validity of matching on "$var is TraitName" in subroutine
> > signatures is correct.  That, and types of hash keys. :)
> 
> Either that, or the Ref value type is designed to wrap an
> implementation type.

Can you elaborate?  Do you mean the two below are equivalent?

# Something that agrees with the Perl5 model
my @array of Array;
my @array is Array of (Ref of (Any is Array) is Scalar)

> I'm not sure which is the case.

Another possible interpretation is that "of TraitName" automatically
exapnds to "of (Any is TraitName)", which will alleviate the need of a
separate "Ref" above:

# Something that does not quite agree with the Perl5 model
my @array of Array;
my @array is Array of (Any is Array of (Any is Scalar))

If so, may I consider it as equivalent to this Haskell code?

class TArray  baseVtype elemVtype where {- ... -} -- Array Trait
class TScalar baseVtype   where {- ... -} -- Scalar Trait

myArray :: (TArray t1 t2, TArray t2 t3, TScalar t3) => t1

That is, "myArray" matches any value type (t1) that is an instance of
the TArray type-class interface, with its elemVtype (t2) is also an
interface of TArray, and t2's elemVtype (t3) must be an instance of
the TScalar type-class.  Which means this equivalency should hold:

Perl6 Trait <===>   Haskell TypeClass
Perl6 ValueType <===>   Haskell Type

Please let me know whether this interpretation is valid. :)

Thanks,
/Autrijus/


pgpFr8L2yNMBS.pgp
Description: PGP signature


Re: Retry: ITypes and VTypes.

2005-02-04 Thread Autrijus Tang
On Fri, Feb 04, 2005 at 06:04:52PM +0800, Autrijus Tang wrote:
> my @array of Array;
> my @array is Array of (Any is Array of (Any is Scalar))
>
> If so, may I consider it as equivalent to this Haskell code?
> 
> class TArray  baseVtype elemVtype where {- ... -} -- Array Trait
> class TScalar baseVtype   where {- ... -} -- Scalar Trait
> 
> myArray :: (TArray t1 t2, TArray t2 t3, TScalar t3) => t1

Hmm, it's actually more subtle than that, because Perl6's Array
does not require that each element have the same value type, so a
closer approximation is via existential types -- i.e. for each
element in an array of value type 't3', there must exist an instance
of "TScalar t3", but each element's value-type may differ from
each other; I think that's what the "Any" above means.

However, I wonder how to talk about an array that can contain elements
of any value type, but all the elements must have the same type.
Is Perl6 capable of expressing such a restraint?

Thanks,
/Autrijus/


pgpv8Wn4uEuA8.pgp
Description: PGP signature


Standard value types in S06.

2005-02-04 Thread Autrijus Tang
"Pair", "Junction" and "Undef" are not list among Perl6's standard
types in S06.  I'm assuming that they are actually basic types for now;
if that is the case, below is a patch to say that.

Thanks,
/Autrijus/

--- S06.pod.origFri Feb  4 04:29:34 2005
+++ S06.pod Fri Feb  4 19:32:53 2005
@@ -626,6 +626,7 @@
 num native floating point
 ref native pointer 
 boolnative boolean
+Undef   Undefined value
 Bit Perl single bit (allows traits, aliasing, etc.)
 Int Perl integer (allows traits, aliasing, etc.)
 Str Perl string (Unicode semantics)
@@ -650,6 +651,8 @@
 Class   Perl 6 standard class namespace
 Object  Perl 6 object
 Grammar Perl 6 pattern matching namespace
+PairPerl pair
+JunctionPerl junction
 ListPerl list
 LazyLazily evaluated Perl list
 Eager   Non-lazily evaluated Perl list


pgpSGbSdeytRp.pgp
Description: PGP signature


Re: Retry: ITypes and VTypes.

2005-02-04 Thread Autrijus Tang
On Fri, Feb 04, 2005 at 01:00:33PM +0100, Miroslav Silovic wrote:
> The problem (in general) with this requirement is that it conflicts with 
> inhericance. Perl6 allows you to extend any type (using 'but' operator, 
> for example) and so, any time you promise that something will be of a 
> certain type, the type's children will be allowed. That's at least the 
> way I read A12. I also think that juntions will have their elements' 
> type's interface and so they can also pose for any type. In other words, 
> you need a real polymorphic object system in Haskell for this to work.
> 
> Fortunately there's one handily described at 
> http://homepages.cwi.nl/~ralf/OOHaskell/

Yes, I have read the OOHaskell paper and traced the hideously clever
HList code.  However, as I'm not doing Perl6->Haskell translator,
but merely a Perl6 interpreter, so OOHaskell's model, whilst
interesting, is of only academic interest to me.  :)

What I'd like to know is (again) the operational semantic of "Array of
Array"; is the two "Array" puns that happens to share a class name, or
is it a shorthand for existential types, or is it a shorthand for the
"Ref" type that looks and acts like the Data.Dynamic type in haskell?
Or something else altogether?

Thanks,
/Autrijus/


pgpKls8O9J6nb.pgp
Description: PGP signature


Read array or hash value from file

2005-02-04 Thread Thu Trieu
Does perl provides function to write array or hash data to file and be able to 
get them back to variable ?
This can be done easily from Vb6 for instance, please do not guide me by using 
Mysql, I mean exporting to a raw "txt" file.
  Somethings like below: (illustrate by php)
$a= array[1..10] = 1,2,3,4,5,6,7,8,9,10 
$name=fopen($filename);
@fwrite($name,$a);
fclose();...
--> afterthat
@fread($name,$b);
then we get
$b= 1,2,3,4,5,6,7,8,9,10
 
Thank,
Trieu



-
Do you Yahoo!?
 Yahoo! Search presents - Jib Jab's 'Second Term'

Re: Retry: ITypes and VTypes.

2005-02-04 Thread Miroslav Silovic
[EMAIL PROTECTED] wrote:
However, I wonder how to talk about an array that can contain elements
of any value type, but all the elements must have the same type.
Is Perl6 capable of expressing such a restraint?
Thanks,
/Autrijus/
 

The problem (in general) with this requirement is that it conflicts with 
inhericance. Perl6 allows you to extend any type (using 'but' operator, 
for example) and so, any time you promise that something will be of a 
certain type, the type's children will be allowed. That's at least the 
way I read A12. I also think that juntions will have their elements' 
type's interface and so they can also pose for any type. In other words, 
you need a real polymorphic object system in Haskell for this to work.

Fortunately there's one handily described at 
http://homepages.cwi.nl/~ralf/OOHaskell/

While we're on the topic, which of the following are true?
3 but "three" ~ int   (false?)
3 but "three" ~ Integer (true?)
3 & 5 ~ int (true?)
3 & 5 ~ Integer (true?)
(Skipping off topic, to Parrot. Sorry. :) ) If 3 & 5 is actually int, 
and this is only determinable at runtime, to me this seems like a 
problem with I# register allocation - ints can't be reliably assigned to 
I# registers. Unless, of course, you autothread at the point when a 
junction has to be cast into an int. Do I understand junction semantics 
correctly?
   Miro




Re: Read array or hash value from file

2005-02-04 Thread Nicholas Clark
On Fri, Feb 04, 2005 at 03:24:19AM -0800, Thu Trieu wrote:
> Does perl provides function to write array or hash data to file and be able 
> to get them back to variable ?

I think you're asking this question in completely the wrong place.
This is a list for discussing the specifications of the yet-to-be-finished
Perl 6 language, whereas you're asking a question about how to do something
in Perl 5.

You will probably get a lot of helpful answers if you post your question on
the "seeks of Perl Wisdom" page at Perlmonks:

http://perlmonks.org/?node=Seekers%20of%20Perl%20Wisdom

Nicholas Clark


Some quick questions.

2005-02-04 Thread Autrijus Tang
Today I have finished implementing 90% of primitive operators; Pugs can
now evaluate most simple expressions, including junctive autothreading
and magical/infinite ranges.  Their implementation are in:

http://wagner.elixus.org/~autrijus/darcs/pugs/Prim.hs

As such, there are some corner cases I couldn't find in the spec; please
correct me if my treatment is wrong:

* What is the value of a pair in numeric context? in string context?

Currently I'm taking the ".value" part as its value.

* What is the value of a reference in any of the scalar contexts?

Currently I'm blindly dereferencing it.

* How many bits are "+^" operating on?

Currently it is using a native Unsigned Int.

* Does "**" flatten recursively?

Currently it only flattens the first level of the list.

* Does "(3&0) and (4|0)" evaluate to "(3&0)" or "False"?

Currently it evaluates to "(3&0)".

Thanks,
/Autrijus/


pgpk3iL9u9fbi.pgp
Description: PGP signature


Reality check

2005-02-04 Thread Juerd
Does this make sense?

my @words = gather {
for =(open '/usr/share/dict/words' err die) {
.=chomp;
next if /<-[a-z]>/;
/$re/ and take { word => $_, score => %scores{ .letters }.sum };
}
} ==> sort { . } is descending, { ..length }, { . };


Juerd
-- 
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html 
http://convolution.nl/gajigu_juerd_n.html


Re: Some quick questions.

2005-02-04 Thread Autrijus Tang
On Sat, Feb 05, 2005 at 04:44:41AM +0800, Autrijus Tang wrote:
> * What is the value of a reference in any of the scalar contexts?
> 
> Currently I'm blindly dereferencing it.

It seems that I got four out of five correct; the "blind referencing"
has an important exception in the references are always (by default)
true.

Here's another quick question:  In S03 zip() is used like this:

for zip(@names, @codes) -> $name, $zip { ... }

But in S04 it becomes:

for zip(@a;@b) -> $a, $b { ... }

Why semicolon?  Is it a special form?  Or am I missing something deeply
equivalent about semicolons and list separators?

Thanks,
/Autrijus/


pgpA2Dk18E15S.pgp
Description: PGP signature