f# - Undocumented `when` keyword usage in FSharp.Core -
looking info statically resolved type parameters inline functions stumbled upon definitions of various primitive operators in fsharp.core:
let inline (+) (x: ^t) (y: ^u) : ^v = checkedadditiondynamic<(^t),(^u),(^v)> x y when ^t : int32 , ^u : int32 = (# "add.ovf" x y : int32 #) when ^t : float , ^u : float = (# "add" x y : float #) // <snip> when ^t : ^t = ((^t or ^u): (static fellow member (+) : ^t * ^u -> ^v) (x,y))
as can seen in snippet above when
keyword used in format of: when expr1 = expr2
various built-in types. i'm guessing sort of compiler equivalent of "if t=int utilize opcode add.ovf, else if ..., else that".
however, not find single reference/explanation kind of syntax in f# documentation. within knowledge of f# explain going on in snippet above?
user carsten has provided next comment reply considers wrong.
the thing is: when
used here has nil documented usages - seems called static conditional optimization , should not used outside core libraries - indeed go on , seek utilize - see cannot unless utilize tricks mentioned in johns reply (other question)
user carsten added additional comment answer:
i added comment - don't think educated guess worth reply - hoped 1 of insiders hanging around set official reply it
the reply referred in carsten's first comment user john palmer in apr 2013 links reply provided on (# ..... #)
syntax, what (# ... #) syntax seen in f3 standard library implementation?
you can utilize have specify --compiling-fslib
(undocumented) , --standalone
flags in code.
user mistermetaphor provided reply quoting posting in forum said following:
embedded il in f# codes. feature officially supported?
not really. 99.9% purpose of feature operations defined in fsharp.core.dll (called fslib.dll in 1.9.2.9 , before).
for other uses of when
keyword see following.
this microsoft document describes using when
keyword additional conditions on matching, match expressions (f#).
this microsoft document describes using when
keyword express constraints generic type parameters, constraints (f#).
also see microsoft document describing pattern matching when
keyword in various settings, pattern matching (f#).
the pattern matching document says next along several examples.
patterns rules transforming input data. used throughout f# language compare info logical construction or structures, decompose info constituent parts, or extract info info in various ways.
the match look document says next along example.
you can utilize when clause specify additional status variable must satisfy match pattern. such clause referred guard. look next when keyword not evaluated unless match made pattern associated guard.
f#
No comments:
Post a Comment