Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Erase the erase function #1460

Merged
merged 3 commits into from
Aug 24, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 3 additions & 25 deletions src/Swarm/Language/Syntax.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ module Swarm.Language.Syntax (
) where

import Control.Lens (Plated (..), Traversal', makeLenses, para, universe, (%~), (^.))
import Control.Monad (void)
import Data.Aeson.Types hiding (Key)
import Data.Data (Data)
import Data.Data.Lens (uniplate)
Expand Down Expand Up @@ -1068,34 +1069,11 @@ unfoldApps trm = NonEmpty.reverse . flip NonEmpty.unfoldr trm $ \case
-- | Erase a 'Syntax' tree annotated with @SrcLoc@ and type
-- information to a bare unannotated 'Term'.
eraseS :: Syntax' ty -> Term
eraseS (Syntax' _ t _) = erase t
eraseS (Syntax' _ t _) = void t

-- | Erase a type-annotated term to a bare term.
erase :: Term' ty -> Term
erase TUnit = TUnit
erase (TConst c) = TConst c
erase (TDir d) = TDir d
erase (TInt n) = TInt n
erase (TAntiInt v) = TAntiInt v
erase (TText t) = TText t
erase (TAntiText v) = TAntiText v
erase (TBool b) = TBool b
erase (TRobot r) = TRobot r
erase (TRef r) = TRef r
erase (TRequireDevice d) = TRequireDevice d
erase (TRequire n e) = TRequire n e
erase (SRequirements x s) = TRequirements x (eraseS s)
erase (TVar s) = TVar s
erase (SDelay x s) = TDelay x (eraseS s)
erase (SPair s1 s2) = TPair (eraseS s1) (eraseS s2)
erase (SLam x mty body) = TLam (lvVar x) mty (eraseS body)
erase (SApp s1 s2) = TApp (eraseS s1) (eraseS s2)
erase (SLet r x mty s1 s2) = TLet r (lvVar x) mty (eraseS s1) (eraseS s2)
erase (SDef r x mty s) = TDef r (lvVar x) mty (eraseS s)
erase (SBind mx s1 s2) = TBind (lvVar <$> mx) (eraseS s1) (eraseS s2)
erase (SRcd m) = TRcd ((fmap . fmap) eraseS m)
erase (SProj s x) = TProj (eraseS s) x
erase (SAnnotate s pty) = TAnnotate (eraseS s) pty
erase = void

------------------------------------------------------------
-- Free variable traversals
Expand Down
Loading