Something, foldr, sugar

(2017-08-04)

I dunno. Does taking away some sugar and infixity make some things more clear?

Some Standard ML:

- nonfix +;
nonfix +
- + (1, 2);
val it = 3 : int
- nonfix ::;
nonfix ::
- :: (1, :: (2, :: (3, nil)));
val it = [1,2,3] : int list
- foldr + 0 (:: (1, :: (2, :: (3, nil))));
val it = 6 : int

(We removed the infix thing from + and :: (the plus function and the list “cons”). They take tupled arguments. Infix 1 + 2 is nonfix + (1, 2), and so on.)

Here, I guess we can say that
foldr + 0 (:: (1, :: (2, :: (3, nil))))
is like equivalent to
+ (1, + (2, + (3, 0))).

And it is maybe more clear how
+ (1, + (2, + (3, 0)))
is similar to the list
0 (:: (1, :: (2, :: (3, nil)))?

(It is like list we started with, but with the list constructors, :: and nil, replaced with + and 0 (the first two values we gave to foldr)).

Also maybe unsurprising that
foldr :: nil (:: (1, :: (2, :: (3, nil))))
will be equivalent to
:: (1, :: (2, :: (3, nil)))
and evaluate to a list rather the same as the one we started with?


(Like, more clear compared to something like saying that
foldr (op +) 0 [1, 2, 3]
is equivalent to
1 + (2 + (3 + 0))?)


And also like maybe not I dunno.