(I know little about quotations, so I may be wrong.)

Are you sure 'coerce' means downcast (:?>)? I would guess that it means upcast (:>).

By on 4/15/2009 4:40 PM ()

The online documentation for Expr.Corce says "Build an expression that represents the coercion of an expression to a type", which is a bit vague.

However, this is valid code:

seq ([|1; 2|] :> seq<int>)

so perhaps you're right...

Thanks Brian!

By on 4/15/2009 5:28 PM ()

For completeness, apparently an explicit downcast will create an "UnboxGeneric" call:

1
2
3
4
5
6
7
8
9
10
11
12
13
 

> <@ fun (e:System.Exception) -> e :?> System.ArgumentException @>;;
val it : Quotations.Expr<(Exception -> ArgumentException)>
= Lambda (e,
        Call (None,
              System.ArgumentException UnboxGeneric[ArgumentException](System.Object),
              [e]))
    {CustomAttributes = [NewTuple (Value ("DebugRange"),
          NewTuple (Value ("stdin"), Value (5), Value (3), Value (5), Value (61)))];
     Raw = ...;
     Type = Microsoft.FSharp.Core.FastFunc`2[System.Exception,System.ArgumentException];}
By on 4/15/2009 5:52 PM ()

That's right, coercions may appear for upcasts, particularly because this may be a change of representation (a struct can implement IEnumerable, and in this case the coercion would be a boxing operation).

For uniformity coercions like these are not eliminated in the elaborated form unless the source and target types are identical.

kind regards

don

By on 4/17/2009 6:26 AM ()

I see, thanks guys.

Further to this, consider these definitions:

1
2
3
4
5
6
7
8
9
10
    
type Hey  = interface end


    type What = interface end


    type Yo() = interface What interface Hey

Now, this quotation:

1
2
3
4
    


    <@@ let x = Yo() :> What in x :?> Hey @@>

produces this:
Let (x, Coerce (NewObject (Void .ctor()), What)
, Call ( None
, Hey UnboxGeneric[Hey](System.Object)
, [x]
)
)

which appears invalid, since x is of type What, not System.Object. Instead, I'd expect to see an explicit boxing like this:

Let (x, Coerce (NewObject (Void .ctor()), What)

, Call ( None
, Hey UnboxGeneric[Hey](System.Object)
, [Call ( None
, System.Object box[What](What)
, [x]
)
]
)
)

what's going on here?

By on 4/17/2009 11:39 AM ()

bump... [:)]

By on 4/21/2009 11:11 AM ()

Hi Matt,

I agree the quotation contains an implicit coercion from What --> Object, inserted for the desugaring of "x :?> Hey"

In general quotations should not contain this kind of implicit coercion and thus this is an inconsistency. We'll record a bug about that.

Thanks!

don

By on 4/23/2009 3:39 PM ()

Ok, thanks a lot Don

By on 4/24/2009 3:15 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper