I agree. In fact, I would even think we may do with a math-like notation. [0..2] and [0..2[ or [0..2) are not the same. Not sure how you could introduce it in a language without adding too much clutter/difficulties in the syntax, though.
I'm all for your upfrom (although in most languages it's an easy enough macro that can be added at the start of any program...)
I actually like what itertools provides in Python. Plently of interesting solutions to iterables. For example, you can do "upfrom(3,10)" by islice(count(3), 10)
But nowadays I wish for SML's/Haskell's version of the same thing, which lets you match multiple arguments at once.
Interesting... I'm also using fun in Caml a lot, and if it's not available alongside function, I guess I'll miss it. I guess you could always use uncurrified expressions, but that's less interesting.
The reason for the inequality is that it covers the negative case more gracefully and guards against nontermination. Yours will choke on negative numbers.
I'd probably write a
in Caml, anyway, but I need to look more into F# syntax...
But maybe the right thing to do was to throw an exception, anyway.
For 0 or for negatives?
By the way: do you actually teach exceptions in your class? Or do you prefer to emphasize algebraic datatypes?
That's... actually a hot question.
Short answer: I do...
It's not required as I understand it (I train students for recruitments in top engineering schools, so there's a national "list" of expected knowledge I have to stick to), but I think it's really useful, so I do it in ML classes (where I have students more interested in CS)
I usually don't in Python classes (which everyone attend in science). But at the same time, some people argue that we should only teach algorithmics, and we shouldn't even use slices or list comprehensions in Python (I disagree on this one), so I have to make some choices, and exceptions catching in Python aren't that important for beginners, I'd say.
(Not) cmpletely unrelated, I still find fun that several people think rising an exception in a loop you catch in a try outside of the loop is a pass to exit the loop, but break is a definitive no-no ^_^
Also, I agree. You need to dive more into F#!
Will definitively do, soon.
Anyway my point is that F# is a first class citizen ML (minus a module system) on one of the most well designed runtimes ever. And with .NET core, it's becoming less and less tied to Windows.
You're pointing maybe the first reason why I've been reluctant to do too much C# (and F#), even with Mono and other tricks.
But Scala (and to a lesser extend a couple others like Clojure) made me overcome my JVM allergy, so maybe (probably) F# will do the job.
That being said, I know the guys behind Caml and used to work in the (large) "organization" that develop it, so I can't jump on a Microsoft variation of it too quickly, I need to show some support ^_^ (and overall, they've done great work to develop functional programming)