pattern_matching/v3.hs

42 lines
1.3 KiB
Haskell
Raw Normal View History

2025-09-02 22:39:32 +03:00
import Data.Map.Strict as Map
import Data.Bifunctor as Bifunctor
import Data.Maybe as Maybe
import Control.Monad as Monad
type Symb = String
infixl 4 :@:
-- %x + 3 := 12
-- addp :: BoxT Int -> Int -> Int -> ???
-- addp :: Out Int -> In Int -> In Int
-- addp :: {x: Box Int} -> {_: Int} -> {_: Int} -> ??? {x: Int}
-- addp :: Box Int -> In Int -> In Int -> Ctx
-- addp :: Box x Int -> Int -> Int -> {x: Int}
-- addp (Box x Int) 3 <- type ??? {_: Int} -> {x: Int}
-- Match ((+') (Box x Int) 3) 12
--------------------------------
--
-- idea: every function returns context (list/map of named terms instead of expr)
-- Branch - split current entity on two subcontexts
-- Name - name current branch
type Ctx = Map Symb Term
data Type = Boo
| NameT Symb Type
| Type :-> Type
| CtxT (Map Symb Type)
deriving (Read,Show, Eq)
data Term = Fls -- const as _
| Tru -- const as _
| Name Symb Type -- encode pattern entities
| Union Term -- union resulting contexts, should be applied to term=ctx
| Var Symb -- get variable from current context as _
| Context Ctx -- direct context return
| Lmb {pat :: Term, body :: Term} -- match context with pattern and exec body, should be applied to term=ctx
| Term :@: Term -- apply term to term
deriving (Read,Show)