On 20/07/2012, at 10:26 PM, Shayne Fletcher wrote:

> On 20/07/2012 07:06, john skaller wrote:
>> The problem I'm trying to solve is that this:
>> 
>>      T * T ^ N
>> 
>> does not currently unify with T^2. It should, with N=1.
> 
> Yep.



Well actually .. I'm not sure. Let me ask this question:

What is the value type and length of the array below?

var x = 1,2;

Did you answer  "int" and "2"?

You're right! Did you answer "int * int" and "1"?

You're right!

Did you answer "int ^ 2" and "1"? You're right also
but this is the same as the last answer.

So we can't tell what the length of the array above actually is: 2 or 1.

This is because Felix doesn't have a specific array constructor.
This trick of using a tuple of all the same type as an array only works
when the same thing for tuples works: there are no tuples of length 1
either (and if there were they'd also be arrays length 1).

Unless I make

        [< 1,2,3,4 >] and [< 1 >]

arrays *distinct* from a non-array value in the second case, we can't
tell the length of an array, because we can't tell the difference between
a non-array and an array. Note we then also need an "unarray" operator:

        var x : int = unarray [< 1 >]; // x is 1

The effect would probably propagate to tuples: as in Python a tuple
of 1 element would exist and be distinct from the value (in fact such a tuple
might be an array of length 1 .. and maybe it would also be distinct!
Not sure].

I'm still looking into this but a concrete rule to distinguish the cases
may not be tenable because of polymorphism. I actually get this
error at the moment:

Weird array thing <T2127>^<T2128> <--> index_11080[<T11222>]
CLIENT ERROR
[bind_exe: fun_return ] return of (index_2158<2158>[<T11222>] ()):
fun return type:
<T11222>
must have same type as return expression:
index_11080[<T11222>]
In /Users/johnskaller/felix/build/release/lib/std/sarray.flx: line 13, cols 14 
to 86
12:      JudyLGet ( (_repr_ a)*.j, i.word, &e, &pk);
13:      var r = if C_hack::isNULL pk then (_repr_ a)*.dflt else (_repr_ 
a)*.a.(size(*pk));
                 
*************************************************************************
14:      return r;

which has eventually lead to the thought I'm trying to do something that doesn't
make sense. This particular unification (shown in the "weird array" message)
succeeded with

        T2126 -> index_11080[T11222] and T2128 -> 1

and i think this is trying (in vain for some reason) to invoke
a varray constructor. the problem may be:

  ctor[t] varray[t]: size =
  ctor[t,N] varray[t] (x:array[t,N]) => 

because these are "ambiguous" in some sense: set t-> size and N->1
(however the first is more specialised so it should win this case).

--
john skaller
skal...@users.sourceforge.net
http://felix-lang.org




------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to