One actual reason (for me) to use objects in #fsharp is polymorphic recursion in members; it is not available on functions. I wish there was a form of object expressions which immediately introduced a type without a separate interface or abstract type.
Example: one would expect this to work, because the function seemingly accepts any 'a but it doesn’t: let rec printSome (a : Option<‘a>) = match a with | Some a -> printfn a | None -> printSome (Some “Fake Some!”)
So when I really need such a function, I’d like to “wrap” it in a member with as little ceremony as possible. Kind of like Scala’s singleton objects. Now I need to define a boilerplate interface and “inplement” it in an object expression.
• • •
Missing some Tweet in this thread? You can try to
force a refresh
I write #fsharp and #haskell daily (and #purescript too) and thought of making a micro-blog comparison of the two. Fun facts and maybe new discoveries for the interested, in no particular order. This will be long and probably slow.
Unlike #fsharp, #haskell has no records, only discriminated unions. It does have something called “record syntax” for DUs.
In #fsharp functions cannot be overloaded. In #haskell it is possible through the “type classes” mechanism, conceived specifically for this.