oflang / ox

A language bring gears and levers to coding
GNU General Public License v3.0
1 stars 0 forks source link

Keep it simple, stupid #3

Open WMJi opened 8 years ago

WMJi commented 8 years ago

Hope LR0 or SLR1 can work for ox

WMJi commented 8 years ago

functions can not change any external variables?

variables in a package can be read by inner codes (functions, package level codes), and can only be written by package level codes...

WMJi commented 8 years ago

Do things from left to right. Do not have to write >> ?

WMJi commented 8 years ago

avoiding parentheses

The $ operator (in Haskell) is for avoiding parentheses. Anything appearing after it will take precedence over anything that comes before.

For example, let's say you've got a line that reads:

putStrLn (show (1 + 1)) If you want to get rid of those parentheses, any of the following lines would also do the same thing:

putStrLn (show $ 1 + 1) putStrLn $ show (1 + 1) putStrLn $ show $ 1 + 1

The primary purpose of the . operator is not to avoid parentheses, but to chain functions. It lets you tie the output of whatever appears on the right to the input of whatever appears on the left. This usually also results in fewer parentheses, but works differently.

Going back to the same example:

putStrLn (show (1 + 1)) (1 + 1) doesn't have an input, and therefore cannot be used with the . operator. show can take an Int and return a String. putStrLn can take a String and return an IO (). You can chain show to putStrLn like this:

(putStrLn . show) (1 + 1) If that's too many parentheses for your liking, get rid of them with the $ operator:

putStrLn . show $ 1 + 1