Inspired by "Parsing CSS with Parsec".
Just quick notes and code that you can play with in REPL.
By @kachayev
Inspired by "Parsing CSS with Parsec".
Just quick notes and code that you can play with in REPL.
By @kachayev
| (ns kleene) | |
| ;; | |
| ;; Inspired by "Regexes, Kleene Algebras and Real Ultimate Power" | |
| ;; http://plastic-idolatry.com/erik/oslo2014.pdf | |
| ;; | |
| ;; What do we want to do?... | |
| ;; | |
| ;; (def p1 (times (Var. "w") (Var. "o") (Var. "w")) | |
| ;; (matches? p1 "wow") ;; true |
| ## Alexey Kachayev, 2014 | |
| ## Link to slides: | |
| ## http://goo.gl/n4ylC4 | |
| ## Basic: | |
| ## type Parser = String -> Tree | |
| ## Composition | |
| ## type Parser = String -> (Tree, String) |
| def heap(el=None): | |
| return (el, None, None) | |
| def union((el1, left1, right1), (el2, left2, right2)): | |
| if el1 is None: return (el2, left2, right2) | |
| if el2 is None: return (el1, left1, right1) | |
| if el1 < el2: | |
| return (el1, union((el2, left2, right2), right1), left1) | |
| else: | |
| return (el2, union((el1, left1, right1), right2), left2) |
| data Pairing a = Empty | Node a [Pairing a] | |
| singleton x = Node x [] | |
| union Empty h2 = h2 | |
| union h1 Empty = h1 | |
| union t1@(Pairing h1 subs1) t2@(Pairing h2 subs) | |
| | h1 < h2 = Pairing h1 t2:subs1 | |
| | otherwise = Pairing h2 t1:subs2 | |
| data Skew a = Empty | Node a (Skew a) (Skew a) | |
| singleton x = Node x Empty Empty | |
| union t1 Empty = t1 | |
| union Emtpy t2 = t2 | |
| union t1@(Node x1 l1 r1) t2@(Node x2 l2 r2) | |
| | x1 <= x2 = Node x1 (union t2 r1) l1 | |
| | otherwise = Node x2 (union t1 r2) l2 | |
| data Pairing a = Empty | Node a [Pairing a] | |
| singleton :: Ord a => a -> Pairing a | |
| singleton x = Node x [] | |
| union :: Ord a => Pairing a -> Pairing a -> Pairing a | |
| union Empty h2 = h2 | |
| union h1 Empty = h1 | |
| union t1@(Pairing h1 subs1) t2@(Pairing h2 subs) | |
| | h1 < h2 = Pairing h1 t2:subs1 |
| iex(1)> import Scala | |
| nil | |
| iex(2)> s = for do | |
| ...(2)> f <- [1,2,3] | |
| ...(2)> g <- [1,2,3] | |
| ...(2)> if (rem f+g, 2) == 0 | |
| ...(2)> yield {f, g*2} | |
| ...(2)> end | |
| iex(3)> Enum.to_list s | |
| [{1, 2}, {1, 6}, {2, 4}, {3, 2}, {3, 6}] |
| import Pipes | |
| # defservice Profile do ... end | |
| # defservice Device do ... end | |
| # defservice Push do ... end | |
| send = pipe do | |
| profile <- Profile.all &1 | |
| badge <- Profile.get_badge_size profile | |
| device <- Device.sessions profile |
| $ mkdir ~/ElixirLang | |
| $ cd ~/ElixirLang | |
| $ brew install kerl | |
| $ kerl build R16B01 r16b01 | |
| $ kerl install r16b01 ~/erlang/r16b01 | |
| $ . ~/erlang/r16b01/activate | |
| $ erl | |
| Erlang R16B01 (erts-5.10.2) [source] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] | |
| Eshell V5.10.2 (abort with ^G) |