7 ms·
Poly/ML?
by hroman 10y ago
Poly/ML?
- cwyers 10y agoNo. I mean, I know Tiobe isn't great, but the only ML-derivative I see on the top 50 is F#. ML and OCaml crack the top 100.
- groovy2shoes 10y agoF# is an OCaml derivative. I'd reckon that OP's feelings about F# would be rather similar to their feelings about OCaml.
- cwyers 10y agoThe only objection to OCaml is "the crufty syntax," which I think F# has taken steps to improve upon.
- sixbrx 10y agoBut F# didn't bring along the beautiful module system from the MLs, nor does it have type classes. Polymorphism there is basically just the OO + generics variety found in C#. That can rub some people (like me) the wrong way.
- ZenoArrow 10y agoF# does have type classes, they're just called interfaces. https://msdn.microsoft.com/en-us/visualfsharpdocs/conceptual/interfaces-%5Bfsharp%5D https://msdn.microsoft.com/en-us/visualfsharpdocs/conceptual...
- lkitching 10y agoType classes are quite different from interfaces. How would you encode the Eq typeclass in F#? .Net has the IEqualityComparer<T> interface but you need to manually pass that around (unlike Eq instances) and you also lose the global uniqueness property.
- ZenoArrow 10y agoYou don't have to rely on the built in interfaces provided by .NET, you can create your own. Just like in Haskell in F# you can use pattern matching against types to define which of the equality operators to use. Also, I'm not sure what you mean by "manually pass that around". When you define a class in Haskell that inherits from a typeclass you reference that typeclass in the header of the new class. You follow the same approach in F# with interfaces.
- lkitching 10y agoBy 'pass around', I mean pass around instances, not definitions. You could define your own Eq interface in F# type IEq<'a> = abstract member eq: 'a -> 'a -> bool but you then need to explicitly pass instances of this interface around into every method that requires it e.g. let allEq (s: 'a seq) (eq: IEq<'a>) = ... whereas the haskell version would receive the Eq instance for the input type implicitly. Typeclass instances are globally unique for each type, which cannot be enforced with the interface solution. If you have an ordered map type, you can be sure the Ord instance used for insertion is the same that is used for retrieval. With the interface approach, clients cannot know which instance to use since there could be multiple implementations. The Haskell approach has its own problems, such as the proliferation of newtype wrappers to manage the dispatch mechanism. Interfaces also hide the representation of one of their arguments (the receiver) whereas typeclasses are just a dictionary of functions.
- ZenoArrow 10y agoI'm not sure I understand all of what you've said, as I'm not familiar with Haskell, but there are at least some Haskell programmers have recognised the similarities between type classes and interfaces. Do you disagree with any of the following? https://wiki.haskell.org/OOP_vs_type_classes#Type_classes_are_like_interfaces.2Fabstract_classes.2C_not_classes_itself https://wiki.haskell.org/OOP_vs_type_classes#Type_classes_ar... "Type classes are like interfaces/abstract classes, not classes itself There is no inheritance and data fields (so type classes are more like interfaces than classes).... For those more familiar with Java/C# rather than C++, type classes resemble interfaces more than the classes. In fact, the generics in those languages capture the notion of parametric polymorphism (but Haskell is a language that takes parametric polymorphism quite seriously, so you can expect a fair amount of type gymnastics when dealing with Haskell), so more precisely, type classes are like generic interfaces. Why interface, and not class? Mostly because type classes do not implement the methods themselves, they just guarantee that the actual types that instantiate the type class will implement specific methods. So the types are like classes in Java/C#. One added twist: type classes can decide to provide default implementation of some methods (using other methods). You would say, then they are sort of like abstract classes. Right. But at the same time, you cannot extend (inherit) multiple abstract classes, can you? So a type class is sort of like a contract: "any type that instantiates this type class will have the following functions defined on them..." but with the added advantage that you have type parameters built-in, so: class Eq a where (==) :: a -> a -> Bool (/=) :: a -> a -> Bool -- let's just implement one function in terms of the other x /= y = not (x == y) is, in a Java-like language: interface Eq<A> { boolean equal(A that); boolean notEqual(A that) { // default, can be overriden return !equal(that); } } And the "instance TypeClass ParticularInstance where ..." definition means "ParticularInstance implements TypeClass { ... }", now, multiple parameter type classes, of course, cannot be interpreted this way."
- groovy2shoes 10y agoThey explicitly said "an ML derivative that's not OCaml". It's not a big leap from that statement to "neither OCaml nor a Caml derivative" given the similarities between the languages. I'm really not at all surprised that if they want to discount OCaml as a successor ML, they'd want to discount F# as well, given the close relationship between the two. Like @hroman, I too was rather puzzled by your initial statement.
- agentgt 10y agoI'm sort of sick of hearing that OCaml has crappy or crufty syntax. I like OCaml's syntax. There is just a sea of useless algol brackets in so many languages. I was sort of sad that Rust fell victim to the damn bracket. At times I don't even think Scala is that much more succinct than modern Java 8 (ala bracket indentation fun). I remember years ago (15 years.. jesus I'm old) discovering OCaml and I couldn't believe how terse the language was for producing native code. If anything I don't like about OCaml syntax is that it actually has an enormous amount of syntactic sugar.
- qbrass 10y agoWas OCaml was your first ML language? It seems that most of the people who find OCaml crufty used Standard ML before OCaml.
- eatonphil 10y agoFor what it's worth, I think OCaml's syntax is one of its weakest points (not to mention syntax extensions...) and I have been writing OCaml 3 years longer than I've been writing Standard ML.
- agentgt 10y agoWell yes I agree if you compare OCaml to Standard ML its syntax is not as good and I do prefer Standard ML over it. However I prefer OCaml over Java, Javascript, Scala (and the bazillion other brace block languages that are the same), and yes even Haskell.
- agentgt 10y agoGuilty as charged.. I did learn OCaml first and from that official green HTML documentation which still appears to be green after 16 years :). My complaint with OCaml was OCamlp and the tedium of creating modules and functors. While AdHoc poly (aka type classes) is not as flexible it is IMO easier to understand, generally less verbose and slightly more elegant than OCaml modules. I'm glad they added first class modules as I recall wanting something like that a long time ago.
- jonsterling 10y agoF# doesn't even have modules. Not really in the SML spirit—it's like if you combined Classic/LCF ML from the 1970s with C#.
- ZenoArrow 10y agoIn the context of ML, what are modules and why are they useful?
- groovy2shoes 10y agoPoly/ML isn't an SML derivative, per se. It's an implementation of Standard ML (and a damn fine one at that).