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
Post a Comment