implement merge maps on import
Haldean Brown
2 years ago
18 | 18 |
main-is: Del.hs
|
19 | 19 |
hs-source-dirs: src
|
20 | 20 |
ghc-options: -Wall -Werror
|
|
21 |
default-extensions:OverloadedStrings, RankNTypes
|
21 | 22 |
default-language: Haskell2010
|
22 | 23 |
other-modules: Language.Del.AST
|
23 | 24 |
, Language.Del.Builtins
|
0 | 0 |
{-# LANGUAGE DataKinds #-}
|
1 | |
{-# LANGUAGE OverloadedStrings #-}
|
2 | 1 |
{-# LANGUAGE RankNTypes #-}
|
3 | 2 |
|
4 | 3 |
module Language.Del.AST where
|
24 | 24 |
| BadNativeName Expr Expr -- expr that's supposed to be the native func
|
25 | 25 |
-- name, full native call expr
|
26 | 26 |
| ApplyHeadNotId Expr
|
|
27 |
| ImportNameClash T.Text [T.Text]
|
27 | 28 |
deriving (Eq)
|
28 | 29 |
|
29 | 30 |
data Artifact a
|
|
81 | 82 |
show (ApplyHeadNotId e) =
|
82 | 83 |
"head of list must be the name of a function in expression:\n\n\t" ++
|
83 | 84 |
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
|
5 | 5 |
import qualified Data.Map.Strict as Map
|
6 | 6 |
|
7 | 7 |
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 |
|
9 | 17 |
|
10 | 18 |
loadImport :: Source -> IO (Artifact AST)
|
11 | 19 |
loadImport = undefined
|