How do I write this member constraint in F#?

It’s not explicitly writing the constraints that is the issue, it’s that the syntax is not so nice that you can place a member constraint on a parameter and then invoke the member in the usual way. The body of walk_the_creature and walk_the_creature2 would be the same here: let inline walk_the_creature_2 (creature:^a when ^a:(member Walk … Read more

Does F# have generic arithmetic support?

As brian mentioned, there is some built-in support for generic arithmethic and you can use ‘static constraints’ which allow you to define some generic functions yourself (although this is a bit limited). In addition to this, you can also use dynamic ‘numeric associations’, which is a bit slower when using in a function, but it … Read more

Returning constrained generics from functions and methods

I think the key to understanding what is going on here is distinguishing between things that are determined dynamically at runtime, and things that are determined statically at compile time. It doesn’t help that, in most languages like Java, protocols (or interfaces) are all about getting polymorphic behavior at run time, whereas in Swift, protocols … Read more