f# - Upcasting and Generics -


i perplexed this. why doesn't work - aren't explicitly telling 't indeed view?

let foo<'t when 't :> view> (v:'t):view = v  error fs0001: expression expected have type view  here has type 't 

msdn:

in many object-oriented languages, upcasting implicit; in f#, rules different. upcasting applied automatically when pass arguments methods on object type. however, let-bound functions in module, upcasting not automatic, unless parameter type declared flexible type.

the :> operator performs static cast, means success of cast determined @ compile time.

the minimal code

let foo<'t when 't :> view> (v:'t):view = v :> _ 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -