interpret Parigot's lambda-mu calculus in Haskell

后端 未结 3 1342
礼貌的吻别
礼貌的吻别 2021-02-06 04:46

One can interpret the lambda calculus in Haskell:

data Expr = Var String | Lam String Expr | App Expr Expr

data Value a = V a | F (Value a -> Value a)

inter         


        
3条回答
  •  [愿得一人]
    2021-02-06 05:13

    Note: this is only a partial answer since I'm not sure how to extend the interpreter.

    This seems like a good use case for DataKinds. The Expr datatype is indexed on a type which is named or unnamed. The regular lambda constructs produce named terms only.

    {-# LANGUAGE GADTs, DataKinds, KindSignatures #-} 
    
    data TermType = Named | Unnamed 
    
    type Var = String
    type MuVar = String 
    
    data Expr (n :: TermType) where 
      Var :: Var -> Expr Unnamed
      Lam :: Var -> Expr Unnamed -> Expr Unnamed
      App :: Expr Unnamed -> Expr Unnamed -> Expr Unnamed 
    

    and the additional Mu and Name constructs can manipulate the TermType.

      ...
      Name :: MuVar -> Expr Unnamed -> Expr Named 
      Mu :: MuVar -> Expr Named -> Expr Unnamed
    

提交回复
热议问题