Really? In what context? Do you have a link or citation I could read?
2,169 karma · joined May 25, 2009
Really? In what context? Do you have a link or citation I could read?
functor MonadUtils (M : MONAD) = struct
(* type annotations not strictly necessary *)
fun sequence (ms : 'a M.monad list) : 'a list M.monad =
let fun mcons (elt, rest) = M.bnd elt (fn e => M.bnd rest (fn r => M.ret (e::r)))
in foldr mcons (M.ret []) ms
end
endTo be fair, Harper's comment is practically a pretty silly proposition. But the primary technical claim of his post (SML supports monads) is true. This is a common issue with Harper: he rarely says anything factually incorrect, but the moral conclusions he draws are out of proportion with the technical points he makes.
Only in really strongly typed languages like Agda can you make the associativity constraint /part of the type/ of the function, and thus statically checked by the compiler; but it's perfectly reasonable to make it part of the specification of the function's behavior that it expects its argument to be associative. (Or, slightly more generally, that the order of reduction is unspecified; in which case only an associative function will produce a totally deterministic result.)
In long:
Haskell has much better concrete syntax, better library and tool support, a more active community, and is subjectively nicer to program in.
Haskell is lazy, SML eager. Haskell catches a lot of flack about this from SML fans. I think the typical arguments against laziness (makes it hard to reason about space usage; just a special-case of eagerness) are not false but overblown (it's harder but not that hard once you get used to it; and yes, you can simulate laziness in an eager language using thunks etc, but that's a Turing tarpit argument). However, in the end I'm not sure laziness is worth it.
Haskell is pure and SML is not. I don't mind the impurity of SML (or any other language), but I think Haskell's purity has some nice side-benefits for a high-level FP language (eg. allows more compiler optimizations). I'm also grateful to it for being the main reason Haskell has support for monads, which I think are a powerful unifying idea well worth their weight even if you don't need them to encapsulate I/O & side-effects.
The big difference is, of course, their module systems. Everything Harper says about Haskell in this regard (https://existentialtype.wordpress.com/2011/04/16/modules-mat...) is true, but I don't think it's as big of an issue as he makes out. Typeclasses give you 90% of what you want, in a much more concise package. I've perhaps wanted ML-style modules & functors once or twice when writing Haskell, and I wish I had typeclasses all the time when writing SML. I could say more on this topic, but this response is already overlong.
However, a reasonable proportion of students seem interested, and a handful are overtly enthusiastic about the course. If I had to guess I'd say it won't be an order-of-magnitude improvement over 212, but it will be significant one, if only because it will reach more students earlier in their undergraduate careers. However, only time will tell.
As for 212's reputation, you and I must run in different circles; I know plenty of FP enthusiasts who got their first taste in 212. I suspect a strong selection bias is at work here.
foo(X) :- bar(X).
means that foo(X) is true if bar(X) is true, not the other way around. So your code would indicate that anything that's not a law is unconstitutional, and anything unconstitutional prohibits free exercise of religion (for example).Indeed, I'm not sure in what situations this tradeoff of cons/decons- for lookup-speed is helpful. If I just need fast lookup, I'll use a mapping structure (hashtable, balanced binary tree, patricia trie, etc). If I need reasonable lookup speed and also standard sequence manipulations, finger trees or ropes seem like a better choice. They're more complex, but if performance is an issue, then it's probably worth it.
Also, a bug/design flaw: You can't store NILs in the terminal position:
> (trellis 1 2)
(1 (2))
> (trellis 1 2 nil)
(1 (2))> This also makes it possible to store only a single copy of short strings, to improve memory efficiency, cache locality, and so on.
He's specifically talking about interning strings. He even links to the wikipedia article on string interning. I recall reading that Lua interns strings by default, and a quick google search seems to confirm my belief. However, with only one example, you're right: interning /all/ strings is unusual. Interning all "short" strings, his suggestion, is a more feasible heuristic, and then (if finding the length of a string is O(1)) comparing two short strings amounts to little more than a pointer comparison. I don't know whether there are any languages that do that.
(I don't have a mouse on my laptop. I have a touchpad, and it is able to scroll by swiping or circular motions, but that didn't work on the page when I tried it.)
Thanks in advance!
> (if #t 'then 'else)
then
> (if #f 'then 'else)
else
'cond, in contrast, takes as many branches as you like, but they're parenthesized like so: > (cond (#f 'a)
(#t (display "I can have a body here!\n")
'b)
(#t 'c))
I can have a body here!
b
In arc, there's just 'if, which is like 'cond with a lot of implicit parenthesization and else-branches: arc> (if t 'then 'else)
then
arc> (if nil 'then) ; if no else-branch is given, nil is implied
nil
arc> (if nil 'a
t (do (prn "'do is like Scheme's 'begin or CL's 'progn.")
'b)
'else)
'do is like Scheme's 'begin or CL's 'progn.
b lambda (x y)
display x
+ x y
corresponds to the S-expression: (lambda (x y)
(display x)
(+ x y))1. If you're not willing to change your keybindings to taste, Emacs basically isn't for you; its default bindings are terrible. I suggest binding switch-to-buffer (C-x b) and other-window (C-x o) to single, easy-to-reach chords (I use C-. and C-' respectively).
2. switch-to-buffer sucks. Use iswitchb-mode; it gives you interactive completion of buffer names with substring matching. It also lists your buffers in most-recently-used order, so switching back-and-forth between two buffers is trivial. (There's also ido-mode, which adds interactive completion to even more things with even more features.)
Basically this is the same issue that emacs has always had: the learning curve is steep and you have to invest some time and explore in order to find settings that work for you. (I'm sure you're happy with your current setup; I'm making this post more for people who might be scared away from Emacs than to try and convert you.)
a) Trailing parentheses just look ugly. I can't really explain why - perhaps it's merely a cultural thing, come about only because lispers are so used to looking at stacked-parenthesis code.
b) Lisp code tends to get very nested. In C or Java code, you rarely get more than 3 trailing braces in a row. In Lisp, if you trail parentheses, you regularly end up with 5 or more lines of nothing but trailing parentheses. This contributes to the ugly factor and makes for a lot of "wasted" whitespace. It's also one of the reasons 2-space indentation is the norm for lisp instead of 4-space.
Honestly, I don't think trailing parentheses makes lisp code particularly easier to read. I agree with noahlt that it's mostly the 2-space versus 4-space indentation issue.
+-------+
| +-+ |
| ^ | |
char *foo[10][20];
^ ^ | |
| +---+ |
-----------+
It mentions, in rule 1, handling tokens of the form [] or [X], but not multiple occurrences of these.This is indeed rather nitpickish of me, but on the other hand, one thing that you at least need to know in that case is in what order you read the numbers - left-to-right, or right-to-left (is foo[10][20] a 10-array of 20-arrays or a 20-array of 10-arrays?). Not mentioning this leaves one (at least, it left me) with the impression that multiple occurrences were already handled by this rule as written, which is, as demonstrated, false.
char *foo[10][20];
The method described would indicate that this is a array 10 of pointers to array 20s of chars.This is incorrect. It is an array 10 of array 20s of pointers to chars.