Generate function of given arity in Haskell using type numbers

前端 未结 4 1375
一向
一向 2021-02-01 23:40

Assume I have encoded the natural numbers in Haskell types, and that I have a way of adding and subtracting from them:

data Zero
data Succ n
-- ...
4条回答
  •  感动是毒
    2021-02-02 00:02

    Inlining Martijn's code gives a very simple solution:

    zero xs = xs
    suc n xs x = n (xs ++ [x])
    buildList n = n []
    

提交回复
热议问题