git.haldean.org del / f431952
implement merge maps on import Haldean Brown 2 years ago
4 changed file(s) with 13 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
1818 main-is: Del.hs
1919 hs-source-dirs: src
2020 ghc-options: -Wall -Werror
21 default-extensions:OverloadedStrings, RankNTypes
2122 default-language: Haskell2010
2223 other-modules: Language.Del.AST
2324 , Language.Del.Builtins
00 {-# LANGUAGE DataKinds #-}
1 {-# LANGUAGE OverloadedStrings #-}
21 {-# LANGUAGE RankNTypes #-}
32
43 module Language.Del.AST where
2424 | BadNativeName Expr Expr -- expr that's supposed to be the native func
2525 -- name, full native call expr
2626 | ApplyHeadNotId Expr
27 | ImportNameClash T.Text [T.Text]
2728 deriving (Eq)
2829
2930 data Artifact a
8182 show (ApplyHeadNotId e) =
8283 "head of list must be the name of a function in expression:\n\n\t" ++
8384 show e ++ "\n"
85 show (ImportNameClash imp overlaps) =
86 "importing " ++ T.unpack imp ++ " causes these names to appear more than once:\n\n\t" ++ show overlaps
55 import qualified Data.Map.Strict as Map
66
77 mergeBinds :: T.Text -> Map.Map T.Text Def -> Map.Map T.Text Def -> Artifact (Map.Map T.Text Def)
8 mergeBinds = undefined
8 mergeBinds alias orig new =
9 let aliaser = \n -> T.concat [alias, ".", n]
10 aliasKeys = Map.mapKeys aliaser new
11 aliased = Map.map (\(Def n t a b) -> (Def (aliaser n) t a b)) aliasKeys
12 overlap = Map.intersection orig aliased
13 in if Map.size overlap > 0
14 then Failure $ ImportNameClash alias (Map.keys overlap)
15 else return $ Map.union orig aliased
16
917
1018 loadImport :: Source -> IO (Artifact AST)
1119 loadImport = undefined