Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F# - what does match...with | :? X as x mean?

Tags:

syntax

f#

Super simple question I'm sure but I don't do F# usually so a bit new to the syntax.

How do I read the following fragment of code:

        match shape.Fill with
          | :? PictureBrush as pb ->
              //....

Specifically, I'm not sure what PictureBrush refers to. There's not really any reference to it anywhere else in this file

like image 873
George Mauer Avatar asked Jul 12 '12 16:07

George Mauer


3 Answers

This the Type Test Pattern.

PictureBrush is a type. shape.Fill matches :? PictureBrush when the Fill property is assignable to that type.

like image 124
vcsjones Avatar answered Nov 15 '22 12:11

vcsjones


Also note that the as allows for binding of a variable to be of that type. So pb will be of type PictureBrush, but will have the exact same value as what shape.Fill resolved to.

like image 40
Guvante Avatar answered Nov 15 '22 10:11

Guvante


Its a type comparison. Like typeof(xx) in C#. So match to type of PictureBrush.

like image 21
stevethethread Avatar answered Nov 15 '22 10:11

stevethethread