On Wed, 2007-07-25 at 01:38 -0700, Erick Tryzelaar wrote:
> So I decided the best way to learn about arrows is to try to implement
> them. However, I'm running into some problems. I've got the
> preliminary typeclass implemented here:
>
> #import <flx.flxh>
>
> fun swap[A, B] (a:A, b:B): (B*A) => (b, a);
>
> typeclass Arrow[M: TYPE->TYPE->TYPE]
> {
> virtual fun arrow[a, b]: (a->b) -> M a b;
> virtual fun bind[a, b, c]: M a b -> M b c -> M a c;
> virtual fun first[a, b, c]: M a b -> M (a*c) (b*c);
> virtual fun second[a, b, c]: M a b -> M (c*a) (c*b);
>
> virtual fun foo[a, b, c] (f:M a b): M (a*c) (c*a) =>
> arrow (the swap[a, c])
> ;
> }
>
> But felix doesn't like this, and reports this:
>
> //Parsing Implementation std.flx
> //Parsing Implementation main.flx
> Questionable meta typing of term: <T4563> * <T4565>
> Questionable meta typing of term: <T4577> * <T4575>
> Questionable meta typing of term: <T4587> * <T4589>
> CLIENT ERROR
> In return (arrow the swap[a, c]);
> Wrong return type,
> expected : (<T4537:(TYPE 0 -> (TYPE 0 -> TYPE 0))> (<T4587> *
> <T4589>)) (<T4589> * <T4587>)
> but we got (<T4537> (<T4587> * <T4589>)) (<T4589> * <T4587>)
> In ./main.flx: line 12 col 3 to line 14 col 3
> 11:
> 12: virtual fun foo[a, b, c] (f:M a b): M (a*c) (c*a) =>
> 13: arrow (the swap[a, c])
> 14: ;
> 15: }
>
>
>
> There are three things I see here. First, why is this type
> questionable?
This means "Skaller has no idea what he's doing". The metatyping
of higher order types is broken.
Basically, it should support a proper kinding system, but I got
rather lost in the implementation and gave up.
> It'd be a little easier to read the return type if my
> named abstract types were used instead of the <T4563> style names. Not
> sure how practical that is though.
It can probably be done, however the current encoding is something like:
`BTYP_var of int * btypecode_t
so
`BTYP_var (42,mt)
which means type variable number 42 with metatype mt.
If this is an ordinary type variable, the meta type with be
`BTYP_type 0
which is written TYPE in Felix source.
> Third, aren't these the same times?
The problem here seems to be one of the terms isn't reduced:
> expected : (<T4537:(TYPE 0 -> (TYPE 0 -> TYPE 0))> (<T4587> *
> <T4589>)) (<T4589> * <T4587>)
> but we got (<T4537> (<T4587> * <T4589>)) (<T4589> * <T4587>)
The first term is some type function of kind
TYPE->TYPE->TYPE
applied to
(A*B)
applied to
(B*A)
but the second term is the ACTUAL application of the particular
function. That is,
TYPE->TYPE->TYPE
is the meta-type of the function, whereas
<T4537>
in the second term is a variable for an actual (type) function,
which has (meta) type TYPE->TYPE->TYPE.
So the compiler is bugged, it doesn't recognize that <T4563>
HAS the type TYPE->TYPE->TYPE, and it should be using the
type it has: instead it is actually applying it.
Of course since it is a variable which isn't instantiated,
it can't apply it, so the term isn't reduced.
--
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language