Generate function of given arity in Haskell using type numbers

前端 未结 4 1343
一向
一向 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-02 00:14

    I see your functional-dependency multiparameter empty-datatype flexibly scoped type variables and raise you a Haskell 98 version! It uses HoleyMonoid which is available on hackage:

    {-# LANGUAGE NoMonomorphismRestriction #-}
    
    import Prelude hiding (id, (.))
    import Control.Category
    import Data.HoleyMonoid
    
    suc n = later (:[]) . n
    
    zero  = id
    one   = suc zero
    two   = suc one
    three = suc two
    
    buildList = run
    

    Testing (feel free to omit any type signatures):

    > run three "one" "two" "three"
    ["one","two","three"]
    

提交回复
热议问题