1{-# LANGUAGE DeriveDataTypeable #-}
2module SourceSyntax.Module where
6import Data.List (intercalate)
7import qualified Data.Map as Map
8import Control.Applicative ((<$>), (<*>))
9import Control.Arrow (second)
11import SourceSyntax.Expression (LExpr)
12import SourceSyntax.Declaration
13import SourceSyntax.Type
14import System.FilePath (joinPath)
15import qualified Type.Type as Type
18 Module [String] Exports Imports [Declaration tipe var]
21type Exports = [String]
23type Imports = [(String, ImportMethod)]
24data ImportMethod = As String | Importing [String] | Hiding [String]
25 deriving (Eq, Ord, Show, Data, Typeable)
27data MetadataModule t v = MetadataModule {
31 imports :: [(String, ImportMethod)],
33 types :: Map.Map String Type.Variable,
34 fixities :: [(Assoc, Int, String)],
35 aliases :: [(String, [String], Type)],
36 datatypes :: [ (String, [String], [(String,[Type])]) ],
37 foreignImports :: [(String, LExpr t v, String, Type)],
38 foreignExports :: [(String, String, Type)]
41type Interfaces = Map.Map String ModuleInterface
43data ModuleInterface = ModuleInterface {
44 iTypes :: Map.Map String Type,
45 iAdts :: [(String, [String], [(String,[Type])])]
48instance Binary ModuleInterface where
49 put modul = put (iTypes modul) >> put (iAdts modul)
50 get = ModuleInterface <$> get <*> get
53canonicalize :: String -> ImportMethod -> ModuleInterface -> ModuleInterface
54canonicalize prefix importMethod interface =
55 let addPrefix name = prefix ++ "." ++ name
59 As name -> (tipe, name ++ "." ++ tipe)
60 Hiding vs -> (tipe, if tipe `elem` vs then addPrefix tipe else tipe)
61 Importing vs -> (tipe, if tipe `elem` vs then tipe else addPrefix tipe)
62 newNames = Map.fromList . map newName $ iAdts interface
64 rename name = Map.findWithDefault name name newNames
66 renameADT (name, tvars, ctors) =
67 (rename name, tvars, map (second (map (renameType rename))) ctors)
69 iTypes = Map.map (renameType rename) (iTypes interface),
70 iAdts = map renameADT (iAdts interface)
73renameType :: (String -> String) -> Type -> Type
75 let rnm = renameType find in
77 Lambda a b -> Lambda (rnm a) (rnm b)
79 Data name ts -> Data (find name) (map rnm ts)
80 EmptyRecord -> EmptyRecord
81 Record fields ext -> Record (Map.map (map rnm) fields) (rnm ext)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list