{ haskell }

  • 使用 Parsec 处理左递归

    |

    在给之前写的 Lisp 解释器之前套上表达式语法时,遇到这样几条文法

    ExprFactor...ExprsExpr,ExprsFactorIntegerApplyIdentify...(Expr)Integer......ApplyFactor(Exprs)\begin{aligned} Expr & \rightarrow Factor ... \\\\ Exprs & \rightarrow Expr , Exprs\\\\ Factor & \rightarrow Integer|Apply|Identify|...|{(} {Expr} {)} \\\\ Integer & \rightarrow... \\\\ ...\\\\ Apply & \rightarrow Factor ( Exprs ) \end{aligned}

    显然,non-terminal ApplyApply 的派生最左端会进入 FactorFactor ,之后又会回到 ApplyApply 。教科书式的左递归。

  • Write You a Scheme

    |

    撸了个 Scheme 解释器,也算是拿 Haskell 做过东西了(虽然只是个玩具

    最大的体会就是,既熟悉了 Haskell,也巩固了 Scheme (虽然看过 SICP 但是并不是很明白它的 quosiquote 和 call/cc 之类的鬼东西

    本来是打算自己定义一门语言(像这个),但是发现挺麻烦的(大雾),而且我比较关心的也是解释执行的过程,于是还是决定把 Scheme 实现一下。大体上是跟着 Write Yourself a Scheme in 48 Hours 来的,在它的基础上增加了 Continuation 之类的玩意儿

  • Haskeller 的 PureScript 试水

    |

    – 讲道理虽然自称 Haskeller ,但是其实我根本不会 Haskell(

    为什么我要尝试 PureScript ?

    因为它是 Haskell 和 JavaScript 生的娃啊。

    Facebook 的 React.js 可以说是给 JavaScript 社区带来了一次 functional programming 的热潮。然而 JavaScript 毕竟不是真正的函数式编程语言——虽然有着 closure 等特性让它可以支持这种独特的范式,但是整体而言它还是基于顺序指令和事件回调的语言。

    PureScript 是一门年轻的语言——现在在 github 上可以查到的最早提交来自于 30 Sep 2013 。它致力于创造一种“类似 haskell 的编程体验”和“生成可读的 JavaScript 代码”。于是,有了它,我们终于可以在项目前端部分中愉快的写“ monoid in the category of endofunctors of X, with product × replaced by composition of endofunctors and unit set by the identity endofunctor ”了(

  • H大综合楼,一跃解千愁

    |
    -- fuck**u.hs
    import Data.List
    import Data.List.Split
    -- *大综合楼
    -- 一跃解千愁
    getFloor :: Int -> String -> String
    getFloor count char =
    "│" ++ fuck char ++ "│"
    where
    fuck = concat.replicate count
    build :: Int -> Int -> Int -> String
    build width height jump =
    concat (top : fuck ++ [ground])
    where
    top = '┌' : replicate (width * 2) '─' ++ "┐\n"
    ground = '┴' : replicate (width * 2) '─' ++ "┴" ++ replicate 10 '─'
    fuck = zipWith `++` (concat (replicate height floors)) overflow
    where
    floors = map (getFloor width) ["┌┐", "└┘"]
    body = [" ╰O╯\n", " /\n", " /)\n"]
    repl' p c = replicate c p
    overflow = replicate ((height - jump) * 2 - 1) "\n" ++ body ++ replicate (jump * 2 - 1) "\n"
    main :: IO ()
    main = do
    putStrLn "综合楼高 综合楼宽 飞翔层数"
    params <- getLine
    let [width, height, jump] = splitOn " " params in
    putStrLn $ build (read width :: Int) (read height :: Int) (read jump :: Int)
    putStrLn "*大综合楼\n一跃解千愁"

    hehe