git.iko.soy/rowtype-yoga/purescript-native
on 70bc922 help sign in
55 lines 1.7 kB history raw
1-----------------------------------------------------------------------------
2--
3-- Module : Language.PureScript.Names
4-- Copyright : (c) Phil Freeman 2013
5-- License : MIT
6--
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
9-- Portability :
10--
11-- |
12--
13-----------------------------------------------------------------------------
15{-# LANGUAGE DeriveDataTypeable #-}
17module Language.PureScript.Names where
19import Data.Data
20import Data.List (inits, intercalate)
22data Ident = Ident String | Op String deriving (Eq, Ord, Data, Typeable)
24instance Show Ident where
25 show (Ident s) = s
26 show (Op op) = '(':op ++ ")"
28newtype ProperName = ProperName { runProperName :: String } deriving (Eq, Ord, Data, Typeable)
30instance Show ProperName where
31 show = runProperName
33data ModulePath = ModulePath [ProperName] deriving (Eq, Ord, Data, Typeable)
35instance Show ModulePath where
36 show (ModulePath segments) = intercalate "." $ map show segments
38subModule :: ModulePath -> ProperName -> ModulePath
39subModule (ModulePath mp) name = ModulePath (mp ++ [name])
41global :: ModulePath
42global = ModulePath []
44data Qualified a = Qualified ModulePath a deriving (Eq, Ord, Data, Typeable)
46instance (Show a) => Show (Qualified a) where
47 show (Qualified (ModulePath names) a) = intercalate "." (map show names ++ [show a])
49qualify :: ModulePath -> Qualified a -> (ModulePath, a)
50qualify mp (Qualified (ModulePath []) a) = (mp, a)
51qualify _ (Qualified mp a) = (mp, a)
53nameResolution :: ModulePath -> Qualified a -> [(ModulePath, a)]
54nameResolution (ModulePath mp) (Qualified (ModulePath []) a) = [ (ModulePath mp', a) | mp' <- reverse $ inits mp ]
55nameResolution _ (Qualified mp a) = [(mp, a)]