14 ms·
A Tour of Standard ML
- cmrdporcupine 7y agoOcaml seems to get more buzz, but about 20 years ago I tried my hand at both OCaml and SML/NJ and found that I actually far preferred the latter. SML is a very nice, consistent, and practical language. Here's a pretty thorough comparison of the two http://adam.chlipala.net/mlcomp/ http://adam.chlipala.net/mlcomp/
- alharith 7y agoOCaml has come many, many, many miles from 20 years ago, and continues to make improvements year to year.
- melling 7y agoSounds like multicore OCaml is finally nearing completion: https://discuss.ocaml.org/t/multicore-ocaml-january-2020-update/5090 https://discuss.ocaml.org/t/multicore-ocaml-january-2020-upd...
- pjmlp 7y agoGreat, although in the age of micro-services and threading exploits, being mostly mult-process isn't that bad.
- mhd 7y agoToday's there's also F#, which is the "" to Ocaml's ";;" and to SML's ";". Concurrent ML is definitely worth looking at.
- andrepd 7y agoI don't get the issue with ;; in ocaml, literally all it does is force evaluation in the repl. You will never write it in code.
- int_19h 7y agoDon't you also need it for top-level declarations in a file?
- wk_end 7y agoThey can (almost?) always just be inferred, I think (it's been a couple of years since I programmed in ocaml daily). I personally like using them anyway. If you've done something wrong I recall the parser can sometimes give better error messages if it has them around to orient itself. And for all the complaints people seem to have you really can grow to like them aesthetically - there's something pleasantly blocky and definitive about them I find, like the satisfying thock of a good keyboard.
- tom_mellior 7y agoNo.
- bjoli 7y agoConcurrentML has a outgrown its name. It is available in many different languages. I recall hearing Mike Sperber saying that his company usually just re-implemened it in whatever language they happened to work in that week. It is a really nice system that is similar to go, but the primitives it gives you are in a way a generalisation of go's concurrency primitives.
- throwaway17_17 7y agoCan you point me in the direction of any reading on this, I’d be interested to hear about it.
- the_why_of_y 7y agoThe canonical source is John Reppy's book: https://www.goodreads.com/book/show/302685.Concurrent_Programming_in_ML https://www.goodreads.com/book/show/302685.Concurrent_Progra... Intro article: https://medium.com/@asolove/synchronizable-abstractions-for-understandable-concurrency-64ae57cd61d1 https://medium.com/@asolove/synchronizable-abstractions-for-... There's an interesting series of blogs by Andy Wingo on comparing CML with Go and implementing it in Guile Scheme: https://wingolog.org/archives/2016/09/20/concurrent-ml-versus-go https://wingolog.org/archives/2016/09/20/concurrent-ml-versu... https://wingolog.org/archives/2016/09/21/is-go-an-acceptable-cml https://wingolog.org/archives/2016/09/21/is-go-an-acceptable... https://wingolog.org/archives/2016/10/12/an-incomplete-history-of-language-facilities-for-concurrency https://wingolog.org/archives/2016/10/12/an-incomplete-histo... https://wingolog.org/archives/2017/06/29/a-new-concurrent-ml https://wingolog.org/archives/2017/06/29/a-new-concurrent-ml
- davidgl 7y agoThe Concurrent ML library for F# is https://github.com/Hopac/Hopac https://github.com/Hopac/Hopac
- agumonkey 7y agoOcaml decided to be on the "large" while sml kept small it seems. I loved that trait (through Dan Grossman's MOOC). To the point that I found it even nicer to interact with than lisp.
- saityi 7y agoThe smallness of SML is a big part of why this is 'A Tour of Standard ML' instead of 'A Tour of OCaml' or 'A Tour of Haskell'. It's small enough to learn in a couple days (in my mind!), but it has all of the niceties of statically typed, immutable functional languages, so it provides a good introduction to those ideas. That said, I love how small it is, too. Every time I go back to SML, I find it refreshing how much power there is in a few simple ideas expressed well.
- agumonkey 7y agothe benefits, how I see them, is that the language never impedes your mind.. there are like 5 ideas, and the rest is pure thinking. but well I was acquainted to typed FP before, to some or the mere mortals (just kidding) it might look like a sad joke.
- nextos 7y agoML for the Working Programmer is also an excellent reference. It demonstrates the construction of a theorem prover. As a matter of fact, Isabelle was built with SML. There's also a famously concise intro to SML (in 22 pages!) by Mads Tofte: https://condor.depaul.edu/dmumaugh/readings/handouts/CSC447/tofte-tips.pdf https://condor.depaul.edu/dmumaugh/readings/handouts/CSC447/...
- yawaramin 7y agoWhat kind of stuff are you making with SML?
- deckar01 7y agoI assumed this was title related to standardized machine learning practices. Expanding "ML" to "Meta Language" would make this title clearer.
- xjia 7y agoAs someone familiar with the name already, expanding it would be very confusing for me.
- deckar01 7y agoAs someone familiar with Standard ML, you probably aren't the target audience of a tour of the language. The goal of this article is obviously to introduce new users to the language. Tricking users into clicking the link by being vague is not constructive way to recruit new users.
- Tomte 7y agoNobody says "Standard Meta Language", though. I find it very irritating how people try to make others give up established words and phrases. There will always be ambiguity. See also "crypto" or the recent spat here on HN about an old SQLite page.
- seanmcdirmid 7y agoI thought the M stood for module?
- cvik 7y agoNah, It's Meta (source: https://en.wikipedia.org/wiki/Standard_ML https://en.wikipedia.org/wiki/Standard_ML). SideNote: I have a friend though, who used it for almost 15 years and thought the M stood for Math before we spook about this.
- deckar01 7y agoThe title is misleading due to ambiguity. It is not clear that "standard" is a common noun or part of a proper name within the title. IMO this violates HN guidelines. Abbreviation is only appropriate when the context is understood. Expanding the abbreviation might not be acceptable, but clarifying that Standard ML is a programming language would prevent this title from being misleading.
- vslira 7y agoDan Grossman's "Programming Languages, Part A" (In Coursera) made me fall in love with SML. Highly recommended.
- platz 7y agoThis course finally made me understand the WHY of FP. Comparing and Contrasting the major programming paradigms at a high level, but also actually writing code was a great combination. Before that I just thought it was only used for people doing math and finance (which wasn't even close to right, lol) SML is kind of like the lisp of FP. It's just the minimal core of parametric polymorphism and hindley-milner type inference, so as a beginner you don't spend thought cycles language-specific features (that would make it more useful as a general purpose language) - you just learn and understand the core concepts and techniques (such as building intuition for how to replace different kinds of loops with recursion and pattern matching) that will apply to all FP/HM languages.
- bgorman 7y ago> SML is kind of like the lisp of FP You don't consider lisp the lisp of FP?
- Tomte 7y agoMost Lisps (and certainly Common Lisp) have enabled a functional style, but were never particularly "pure". You have to squint a little bit and gloss over some parts to call them functional programming languages. Haskell is the poster child, but quite rich in syntax and concepts. So while I wouldn't really agree with grandparent, it's at least defensible to see Standard ML as a small core, a kernel of functional programming languages.
- wirrbel 7y agoI think here it is important to note, that the definition of Functional Programming is kind of fluid and has changed considerably over the decades. For a long time, there was no distinction between pure- and non-pure FP langauges and Lisp was certainly considered a FP lang. Yes, Lisps are typically not pure FP, but they are still FP (unless you define FP to mean pure FP, but that's kind of not in line with usage of the terms). That being said, much Lisp code (CL or Scheme alike) is probably as functional in style as Python code.
- platz 7y agoDoes anyone know how fast MLton (whole-program optimization) programs run in comparison to other languages?
- scns 7y agoFaster than C years ago, nowadays it may be different because of all the optimization work put into C compilers. Long compile times though.
- rscho 7y agohttp://www.ffconsultancy.com/languages/ray_tracer/index.html http://www.ffconsultancy.com/languages/ray_tracer/index.html
- cannam 7y agoObviously depends on what you're doing, but in my experience it generally isn't as fast as the C++ I write and compile with a modern compiler. Maybe comparable with other optimised compiled languages with GC. It's not magically fast, but it is quite good at avoiding unexpected slow cases - which can help it "win" even against C++ sometimes. I generally test with MLton and Poly/ML, and MLton does not always produce faster executables, though most of the time it does. Poly/ML is a good compiler as well, and it has much faster compile times.
- platz 7y agoI assume there is a lot of pointer indirection as is the norm in FP languages that hurts performance quite a bit
- cannam 7y agoYep, I guess it doesn't quite reflect the modern reality for memory and cache access there - although at least primitive types are unboxed, inlined in arrays and records, and represented as machine types. There are probably more opportunities to do that in a whole-program compiler, which doesn't need to carry type information between modules. I believe it also doesn't do SIMD auto-vectorization, which is a recent improvement in C++ compilers that's made a difference to some of my own code.
- cannam 7y agoThis is neat, and I didn't spot any mistakes in my first very light skim through. One practical nit is that the position of the "forward" button moves around depending on how long the section title is, so you have to keep chasing it. Possibly it could move to the left of the section title, so back and forward buttons are clustered together in a fixed place?
- saityi 7y agoYep! I will get that fixed. Thank you for the feedback! If you find anything else, issues and feedback are also welcome on the issue tracking @ https://github.com/Saityi/a-tour-of-standard-ml/issues https://github.com/Saityi/a-tour-of-standard-ml/issues -- I'm primarily a backend engineer, and this is my first foray into frontend; even nitpicks like this are very welcome. :)
- deleted 7y ago[deleted]
- donpdonp 7y agoVery clearly written, easy to consume, easy to navigate. Thank you for this!
- saityi 7y agoThank you for checking it out!
- hajile 7y agoTo this day, I don't understand why Google made Go instead of working off of SML. While the go ecosystem is better due to the millions of man-hours poured into it, the language is inferior in every way. To elaborate, CML is better than golang's channels and isn't broken (requiring mutexes over channels to avoid breaking qualifies as broken). SML syntax is simpler to learn, but still offers much more powerful abstractions with pattern matching. SML uses options instead of null pointer exceptions. Hindley-Milner types are clearly superior to Golang's type system (especially things like empty interface). SML has had generics for almost 25 years now while go languishes. SML has immutable data structures and they are the default for almost everything. Golang has implicit types, but SML's implicit types are much better -- especially structurally-typed records. SML's modules are amazing and simply have no comparison in go. Finally, SuccessorML is doing work toward adding a few new features to the language (for example, module type classes), but the language has an actual specification that anyone can implement (and many have) rather than the implementation effectively being the spec.
- mumblemumble 7y agoYour elaboration could as well be described as a list of language features that SML has, and that Go's developers have publicly said are undesirable.
- hajile 7y agoI know they simply cannot have several of them due to the language design choices. I know they are working on some like generics. Others like sounder typing, better type inference, and functioning concurrency primitives seem like sound goals for any language that already has those things. Which of those features have they said the don't want?
- zelly 7y agoPL theoretic superiority was not the design goal. Golang was intended to be a pragmatic, bread-and-butter language for large teams with churn. Bad code needs to be screamingly obvious. It also needs to be very easy to learn. FP langs can never fill this role because it's fundamentally more difficult to think in FP terms than imperative terms. Maybe for small internal projects. (But if it's successful, it'll get rewritten in Go/Java/C++; people simply can't handle FP.)
- eatonphil 7y agoIf you'd like to see more Standard ML, there's a small community on Reddit. https://www.reddit.com/r/sml/ https://www.reddit.com/r/sml/
- dmix 7y agoThe automatic currying of functions is awesome, even if the declaration syntax would take some time to get used to, although it's quite similar to the new JS anonymous fn declaration (x => x + 1), or maybe the inspiration is reversed. I had the same problem getting used to Nim with it's Pascal inspired syntax. But being different is rarely a bad thing as long as it works.
- madhadron 7y ago> it's quite similar to the new JS anonymous fn declaration (x => x + 1), or maybe the inspiration is reversed. Yup, that family of syntax descends from Standard ML.
- danielrk 7y agoI love Standard ML. As an undergrad, I wrote a compiler in it (through Zhong Shao's course at Yale), and it remains the most fun I've had using a programming language, let alone a functional programming language. The syntax is so simple yet it is extremely expressive. Hindley-Milner types are great, and the pattern matching is slick. SML also strikes a logical balance between purity and practicality.
- plinkplonk 7y agoSML is a great language, but the tooling around it wasn't so hot the last time I checked (admittedly more than a decade ago. With a medium sized ( a few ten thousand lines) project I had weird build errors and in the end wrote a makefile. Not fun).
- tom_mellior 7y agoAt https://saityi.github.io/sml-tour/tour/02-05-recursion.html https://saityi.github.io/sml-tour/tour/02-05-recursion.html the claim that "This is safe [...]; it will not explode the stack" is fishy. The function as written is not "syntactically" tail-recursive. A sufficiently heroic compiler could rewrite this example into a tail-recursive accumulator-based one, but is that really required by the specification and commonly implemented in ML compilers?
- saityi 7y agoYou are correct, and I will fix it. The goal here was to encourage recursion and assuage fears of recursion coming from other languages: if I remember correctly, Standard ML does define semantics around 'expansive expressions' which make them /safer/ than I think most imperative programmers (my targeted audience) would expect, but this particular example would throw an exception. To fix it, I will rewrite this section to say that the standard requires optimising /tail-recursive/ calls away, and modify the example to be iteratively recursive, but I'd still like to assuage fears of recursion in the tour. The 'while' loop in SML is actually just a derived form, and is rewritten to recursion; there is no looping in the language. Do you have any suggestions for rewording? This is a work in progress that I was looking for feedback on :) Thank you! If you see anything else fishy, please let me know.
- tom_mellior 7y agoThanks for your answer! I don't have any specific wording suggestions. If you're willing to add a specific section on tail recursion, I think you might leave this example in place (with the first paragraph of the current text) and then show a tail-recursive version in the next step (with a slightly modified version of the second paragraph of the current text).