Imports.hs 17.6 KB
Newer Older
Björn Peemöller 's avatar
Björn Peemöller committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
{- |
    Module      :  $Header$
    Description :  Importing interface declarations
    Copyright   :  (c) 2000-2003, Wolfgang Lux
                       2011, Björn Peemöller (bjp@informatik.uni-kiel.de)
    License     :  OtherLicense

    Maintainer  :  bjp@informatik.uni-kiel.de
    Stability   :  experimental
    Portability :  portable

    This module provides the function 'importModules' to bring the imported
    entities into the module's scope, and the function 'qualifyEnv' to
    qualify the environment prior to computing the export interface.
-}
module Imports (importModules, qualifyEnv) where

import qualified Data.Map as Map
import Data.Maybe
import qualified Data.Set as Set

import Curry.Base.Ident
import Curry.Syntax

import Base.CurryTypes (toQualType, toQualTypes)
26
import Base.Messages (Message, errorMessage, posErr, internalError)
Björn Peemöller 's avatar
Björn Peemöller committed
27
import Base.TopEnv
Björn Peemöller 's avatar
Björn Peemöller committed
28 29 30
import Base.Types

import Env.Interface
Björn Peemöller 's avatar
Björn Peemöller committed
31
import Env.ModuleAlias (importAliases)
Björn Peemöller 's avatar
Björn Peemöller committed
32 33 34 35 36 37
import Env.OpPrec
import Env.TypeConstructors
import Env.Value

import CompilerEnv
import CompilerOpts
38
import Records (expandTCValueEnv, expandValueEnv)
Björn Peemöller 's avatar
Björn Peemöller committed
39 40 41

-- |The function 'importModules' brings the declarations of all
-- imported interfaces into scope for the current module.
42 43
importModules :: Options -> Module -> InterfaceEnv -> CompilerEnv
importModules opts (Module mid _ imps _) iEnv
44
  = expandTCValueEnv opts
45 46
  $ importUnifyData
  $ foldl importModule initEnv imps
Björn Peemöller 's avatar
Björn Peemöller committed
47 48
  where
    initEnv = (initCompilerEnv mid)
49 50
      { aliasEnv     = importAliases     imps -- import module aliases
      , interfaceEnv = iEnv                   -- imported interfaces
Björn Peemöller 's avatar
Björn Peemöller committed
51 52
      }
    importModule env (ImportDecl _ m q asM is) = case Map.lookup m iEnv of
53 54 55
      Just intf -> importInterface (fromMaybe m asM) q is intf env
      Nothing   -> internalError $ "Imports.importModules: no interface for "
                                   ++ show m
Björn Peemöller 's avatar
Björn Peemöller committed
56 57 58 59 60

-- ---------------------------------------------------------------------------
-- Importing an interface into the module
-- ---------------------------------------------------------------------------

61
-- Three kinds of environments are computed from the interface:
Björn Peemöller 's avatar
Björn Peemöller committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
--
-- 1. The operator precedences
-- 2. The type constructors
-- 3. The types of the data constructors and functions (values)
--
-- Note that the original names of all entities defined in the imported module
-- are qualified appropriately. The same is true for type expressions.

type IdentMap    = Map.Map Ident

type ExpPEnv     = IdentMap PrecInfo
type ExpTCEnv    = IdentMap TypeInfo
type ExpValueEnv = IdentMap ValueInfo

-- When an interface is imported, the compiler first transforms the
-- interface into these environments. If an import specification is
-- present, the environments are restricted to only those entities which
-- are included in the specification or not hidden by it, respectively.
-- The resulting environments are then imported into the current module
-- using either a qualified import (if the module is imported qualified)
-- or both a qualified and an unqualified import (non-qualified import).

importInterface :: ModuleIdent -> Bool -> Maybe ImportSpec -> Interface
                -> CompilerEnv -> CompilerEnv
importInterface m q is i env = env
  { opPrecEnv = importEntities m q vs id              mPEnv  $ opPrecEnv env
  , tyConsEnv = importEntities m q ts (importData vs) mTCEnv $ tyConsEnv env
  , valueEnv  = importEntities m q vs id              mTyEnv $ valueEnv  env
  }
Björn Peemöller 's avatar
Björn Peemöller committed
91 92 93 94 95 96 97 98
  where
  mPEnv  = intfEnv bindPrec i -- all operator precedences
  mTCEnv = intfEnv bindTC   i -- all type constructors
  mTyEnv = intfEnv bindTy   i -- all values
  -- all imported type constructors / values
  expandedSpec = maybe [] (expandSpecs m mTCEnv mTyEnv) is
  ts = isVisible is (Set.fromList $ foldr addType  [] expandedSpec)
  vs = isVisible is (Set.fromList $ foldr addValue [] expandedSpec)
Björn Peemöller 's avatar
Björn Peemöller committed
99

100 101 102 103 104 105 106 107 108 109
addType :: Import -> [Ident] -> [Ident]
addType (Import            _) tcs = tcs
addType (ImportTypeWith tc _) tcs = tc : tcs
addType (ImportTypeAll     _) _   = internalError "Imports.addType"

addValue :: Import -> [Ident] -> [Ident]
addValue (Import            f) fs = f : fs
addValue (ImportTypeWith _ cs) fs = cs ++ fs
addValue (ImportTypeAll     _) _  = internalError "Imports.addValue"

Björn Peemöller 's avatar
Björn Peemöller committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
isVisible :: Maybe ImportSpec -> Set.Set Ident -> Ident -> Bool
isVisible (Just (Importing _ _)) xs = (`Set.member`    xs)
isVisible (Just (Hiding    _ _)) xs = (`Set.notMember` xs)
isVisible Nothing                _  = const True

importEntities :: Entity a => ModuleIdent -> Bool -> (Ident -> Bool)
               -> (a -> a) -> IdentMap a -> TopEnv a -> TopEnv a
importEntities m q isVisible' f mEnv env =
  foldr (uncurry (if q then qualImportTopEnv m else importUnqual m)) env
        [(x,f y) | (x,y) <- Map.toList mEnv, isVisible' x]
  where importUnqual m' x y = importTopEnv m' x y . qualImportTopEnv m' x y

importData :: (Ident -> Bool) -> TypeInfo -> TypeInfo
importData isVisible' (DataType tc n cs) =
  DataType tc n (map (>>= importConstr isVisible') cs)
importData isVisible' (RenamingType tc n nc) =
  maybe (DataType tc n []) (RenamingType tc n) (importConstr isVisible' nc)
importData _ (AliasType tc n ty) = AliasType tc n ty

importConstr :: (Ident -> Bool) -> DataConstr -> Maybe DataConstr
importConstr isVisible' dc@(DataConstr c _ _)
  | isVisible' c = Just dc
  | otherwise    = Nothing

-- ---------------------------------------------------------------------------
-- Building the initial environment
-- ---------------------------------------------------------------------------

-- In a first step, the four export environments are initialized from
-- the interface's declarations. This step also qualifies the names of
-- all entities defined in (but not imported into) the interface with its
-- module name.

intfEnv :: (ModuleIdent -> IDecl -> IdentMap a -> IdentMap a)
        -> Interface -> IdentMap a
145
intfEnv bind (Interface m _ ds) = foldr (bind m) Map.empty ds
Björn Peemöller 's avatar
Björn Peemöller committed
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189

-- operator precedences
bindPrec :: ModuleIdent -> IDecl -> ExpPEnv -> ExpPEnv
bindPrec m (IInfixDecl _ fix p op) =
  Map.insert (unqualify op) (PrecInfo (qualQualify m op) (OpPrec fix p))
bindPrec _ _ = id

bindTCHidden :: ModuleIdent -> IDecl -> ExpTCEnv -> ExpTCEnv
bindTCHidden m (HidingDataDecl _ tc tvs) =
  bindType DataType m (qualify tc) tvs []
bindTCHidden m d = bindTC m d

-- type constructors
bindTC :: ModuleIdent -> IDecl -> ExpTCEnv -> ExpTCEnv
bindTC m (IDataDecl _ tc tvs cs) mTCEnv
  | unqualify tc `Map.member` mTCEnv = mTCEnv
  | otherwise = bindType DataType m tc tvs (map (fmap mkData) cs) mTCEnv
  where
   mkData (ConstrDecl _ evs c tys) =
     DataConstr c (length evs) (toQualTypes m tvs tys)
   mkData (ConOpDecl _ evs ty1 c ty2) =
     DataConstr c (length evs) (toQualTypes m tvs [ty1,ty2])

bindTC m (INewtypeDecl _ tc tvs (NewConstrDecl _ evs c ty)) mTCEnv =
  bindType RenamingType m tc tvs
 (DataConstr c (length evs) [toQualType m tvs ty]) mTCEnv

bindTC m (ITypeDecl _ tc tvs ty) mTCEnv
  | isRecordExtId tc' =
    bindType AliasType m (qualify (fromRecordExtId tc')) tvs
   (toQualType m tvs ty) mTCEnv
  | otherwise =
    bindType AliasType m tc tvs (toQualType m tvs ty) mTCEnv
  where tc' = unqualify tc

bindTC _ _ mTCEnv = mTCEnv

bindType :: (QualIdent -> Int -> a -> TypeInfo) -> ModuleIdent -> QualIdent
         -> [Ident] -> a -> ExpTCEnv -> ExpTCEnv
bindType f m tc tvs = Map.insert (unqualify tc)
                    . f (qualQualify m tc) (length tvs)

-- functions and data constructors
bindTy :: ModuleIdent -> IDecl -> ExpValueEnv -> ExpValueEnv
190 191
bindTy m (IDataDecl _ tc tvs cs) env =
  foldr (bindConstr m tc' tvs $ constrType tc' tvs) env $ catMaybes cs
Björn Peemöller 's avatar
Björn Peemöller committed
192
  where tc' = qualQualify m tc
193 194
bindTy m (INewtypeDecl _ tc tvs nc) env =
  bindNewConstr m tc' tvs (constrType tc' tvs) nc env
Björn Peemöller 's avatar
Björn Peemöller committed
195
  where tc' = qualQualify m tc
196
bindTy m (ITypeDecl _ r _ (RecordType fs _)) env =
197
  foldr (bindRecordLabels m r') env fs
198 199 200 201
  where r' = qualifyWith m $ fromRecordExtId $ unqualify r
bindTy m (IFunctionDecl _ f a ty) env = Map.insert (unqualify f)
  (Value (qualQualify m f) a (polyType (toQualType m [] ty))) env
bindTy _ _ env = env
Björn Peemöller 's avatar
Björn Peemöller committed
202 203 204

bindConstr :: ModuleIdent -> QualIdent -> [Ident] -> TypeExpr -> ConstrDecl
           -> ExpValueEnv -> ExpValueEnv
205 206 207 208 209 210
bindConstr m tc tvs ty0 (ConstrDecl _ evs c tys) = Map.insert c $
  DataConstructor (qualifyLike tc c) (length tys) $
  constrType' m tvs evs (foldr ArrowType ty0 tys)
bindConstr m tc tvs ty0 (ConOpDecl _ evs ty1 op ty2) = Map.insert op $
  DataConstructor (qualifyLike tc op) 2 $
  constrType' m tvs evs (ArrowType ty1 (ArrowType ty2 ty0))
Björn Peemöller 's avatar
Björn Peemöller committed
211 212 213

bindNewConstr :: ModuleIdent -> QualIdent -> [Ident] -> TypeExpr
              -> NewConstrDecl -> ExpValueEnv -> ExpValueEnv
214 215 216 217 218 219 220 221 222 223 224
bindNewConstr m tc tvs ty0 (NewConstrDecl _ evs c ty1) = Map.insert c $
  NewtypeConstructor (qualifyLike tc c) $
  constrType' m tvs evs (ArrowType ty1 ty0)

constrType' :: ModuleIdent -> [Ident] -> [Ident] -> TypeExpr -> ExistTypeScheme
constrType' m tvs evs ty = ForAllExist (length tvs) (length evs)
                                       (toQualType m tvs ty)

qualifyLike :: QualIdent -> Ident -> QualIdent
qualifyLike x = maybe qualify qualifyWith (qualidMod x)

225 226 227
bindRecordLabels :: ModuleIdent -> QualIdent -> ([Ident], TypeExpr)
                 -> ExpValueEnv -> ExpValueEnv
bindRecordLabels m r (ls, ty) env = foldr bindLbl env ls
228
  where
229 230 231 232 233
  bindLbl l = Map.insert l (lblInfo l)
  lblInfo l = Label (qualify l) r (polyType $ toQualType m [] ty)

constrType :: QualIdent -> [Ident] -> TypeExpr
constrType tc tvs = ConstructorType tc $ map VariableType tvs
Björn Peemöller 's avatar
Björn Peemöller committed
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274

-- ---------------------------------------------------------------------------
-- Expansion of the import specification
-- ---------------------------------------------------------------------------

-- After the environments have been initialized, the optional import
-- specifications can be checked. There are two kinds of import
-- specifications, a ``normal'' one, which names the entities that shall
-- be imported, and a hiding specification, which lists those entities
-- that shall not be imported.
--
-- There is a subtle difference between both kinds of
-- specifications: While it is not allowed to list a data constructor
-- outside of its type in a ``normal'' specification, it is allowed to
-- hide a data constructor explicitly. E.g., if module \texttt{A} exports
-- the data type \texttt{T} with constructor \texttt{C}, the data
-- constructor can be imported with one of the two specifications
--
-- import A (T(C))
-- import A (T(..))
--
-- but can be hidden in three different ways:
--
-- import A hiding (C)
-- import A hiding (T (C))
-- import A hiding (T (..))
--
-- The functions \texttt{expandImport} and \texttt{expandHiding} check
-- that all entities in an import specification are actually exported
-- from the module. In addition, all imports of type constructors are
-- changed into a \texttt{T()} specification and explicit imports for the
-- data constructors are added.

expandSpecs :: ModuleIdent -> ExpTCEnv -> ExpValueEnv -> ImportSpec
            -> [Import]
expandSpecs m tcEnv tyEnv (Importing _ is) =
  concatMap (expandImport m tcEnv tyEnv) is
expandSpecs m tcEnv tyEnv (Hiding _ is) =
  concatMap (expandHiding m tcEnv tyEnv) is

expandImport :: ModuleIdent -> ExpTCEnv -> ExpValueEnv -> Import -> [Import]
Björn Peemöller 's avatar
Björn Peemöller committed
275 276 277 278 279 280
expandImport m tcEnv tyEnv (Import             x) =
  expandThing m tcEnv tyEnv x
expandImport m tcEnv _     (ImportTypeWith tc cs) =
  [expandTypeWith m tcEnv tc cs]
expandImport m tcEnv _     (ImportTypeAll     tc) =
  [expandTypeAll  m tcEnv tc   ]
Björn Peemöller 's avatar
Björn Peemöller committed
281 282 283

expandHiding :: ModuleIdent -> ExpTCEnv -> ExpValueEnv -> Import -> [Import]
expandHiding m tcEnv tyEnv (Import             x) = expandHide m tcEnv tyEnv x
Björn Peemöller 's avatar
Björn Peemöller committed
284 285 286 287
expandHiding m tcEnv _     (ImportTypeWith tc cs) =
  [expandTypeWith m tcEnv tc cs]
expandHiding m tcEnv _     (ImportTypeAll     tc) =
  [expandTypeAll  m tcEnv tc   ]
Björn Peemöller 's avatar
Björn Peemöller committed
288 289 290 291 292 293 294 295

-- try to expand as type constructor
expandThing :: ModuleIdent -> ExpTCEnv -> ExpValueEnv -> Ident -> [Import]
expandThing m tcEnv tyEnv tc = case Map.lookup tc tcEnv of
  Just _  -> expandThing' m tyEnv tc $ Just [ImportTypeWith tc []]
  Nothing -> expandThing' m tyEnv tc Nothing

-- try to expand as function / data constructor
Björn Peemöller 's avatar
Björn Peemöller committed
296 297
expandThing' :: ModuleIdent -> ExpValueEnv -> Ident -> Maybe [Import]
             -> [Import]
Björn Peemöller 's avatar
Björn Peemöller committed
298 299
expandThing' m tyEnv f tcImport = case Map.lookup f tyEnv of
  Just v
300
    | isConstr v -> fromMaybe (errorMessage $ errImportDataConstr m f) tcImport
Björn Peemöller 's avatar
Björn Peemöller committed
301
    | otherwise  -> Import f : fromMaybe [] tcImport
302 303
  Nothing -> fromMaybe (errorMessage $ errUndefinedEntity m f) tcImport
  where isConstr (DataConstructor  _ _ _) = True
Björn Peemöller 's avatar
Björn Peemöller committed
304
        isConstr (NewtypeConstructor _ _) = True
305
        isConstr (Value            _ _ _) = False
Björn Peemöller 's avatar
Björn Peemöller committed
306 307 308 309 310 311 312 313 314
        isConstr (Label            _ _ _) = False

-- try to hide as type constructor
expandHide :: ModuleIdent -> ExpTCEnv -> ExpValueEnv -> Ident -> [Import]
expandHide m tcEnv tyEnv tc = case Map.lookup tc tcEnv of
  Just _  -> expandHide' m tyEnv tc $ Just [ImportTypeWith tc []]
  Nothing -> expandHide' m tyEnv tc Nothing

-- try to hide as function / data constructor
Björn Peemöller 's avatar
Björn Peemöller committed
315 316
expandHide' :: ModuleIdent -> ExpValueEnv -> Ident -> Maybe [Import]
            -> [Import]
Björn Peemöller 's avatar
Björn Peemöller committed
317 318
expandHide' m tyEnv f tcImport = case Map.lookup f tyEnv of
  Just _  -> Import f : fromMaybe [] tcImport
319
  Nothing -> fromMaybe (errorMessage $ errUndefinedEntity m f) tcImport
Björn Peemöller 's avatar
Björn Peemöller committed
320 321 322

expandTypeWith ::  ModuleIdent -> ExpTCEnv -> Ident -> [Ident] -> Import
expandTypeWith m tcEnv tc cs = case Map.lookup tc tcEnv of
323 324 325 326 327 328 329 330
  Just (DataType     _ _                cs') -> ImportTypeWith tc $
    map (checkConstr [c | Just (DataConstr c _ _) <- cs']) cs
  Just (RenamingType _ _ (DataConstr c _ _)) -> ImportTypeWith tc $
    map (checkConstr [c]) cs
  Just (AliasType    _ _ (TypeRecord  fs _)) -> ImportTypeWith tc $
    map (checkLabel [l | (l, _) <- fs] . renameLabel) cs
  Just (AliasType _ _ _) -> errorMessage $ errNonDataType tc
  Nothing                -> errorMessage $ errUndefinedEntity m tc
Björn Peemöller 's avatar
Björn Peemöller committed
331
  where
332 333 334 335 336 337 338
  checkConstr cs' c
    | c `elem` cs' = c
    | otherwise    = errorMessage $ errUndefinedDataConstr tc c
  checkLabel ls' l
    | l `elem` ls' = l
    | otherwise    = errorMessage $ errUndefinedLabel tc l

Björn Peemöller 's avatar
Björn Peemöller committed
339 340 341

expandTypeAll :: ModuleIdent -> ExpTCEnv -> Ident -> Import
expandTypeAll m tcEnv tc = case Map.lookup tc tcEnv of
342 343 344 345 346 347 348 349
  Just (DataType     _ _                 cs) -> ImportTypeWith tc
    [c | Just (DataConstr c _ _) <- cs]
  Just (RenamingType _ _ (DataConstr c _ _)) -> ImportTypeWith tc
    [c]
  Just (AliasType    _ _ (TypeRecord  fs _)) -> ImportTypeWith tc
    [l | (l, _) <- fs]
  Just (AliasType _ _ _) -> errorMessage $ errNonDataType tc
  Nothing                -> errorMessage $ errUndefinedEntity m tc
Björn Peemöller 's avatar
Björn Peemöller committed
350 351 352 353 354 355 356 357 358 359 360

-- ---------------------------------------------------------------------------

-- After all modules have been imported, the compiler has to ensure that
-- all references to a data type use the same list of constructors.

importUnifyData :: CompilerEnv -> CompilerEnv
importUnifyData cEnv = cEnv { tyConsEnv = importUnifyData' $ tyConsEnv cEnv }

importUnifyData' :: TCEnv -> TCEnv
importUnifyData' tcEnv = fmap (setInfo allTyCons) tcEnv
Björn Peemöller 's avatar
Björn Peemöller committed
361 362 363 364 365 366
  where
  setInfo tcs t   = fromJust $ Map.lookup (origName t) tcs
  allTyCons       = foldr (mergeData . snd) Map.empty $ allImports tcEnv
  mergeData t tcs =
    Map.insert tc (maybe t (fromJust . merge t) $ Map.lookup tc tcs) tcs
    where tc = origName t
Björn Peemöller 's avatar
Björn Peemöller committed
367 368 369

-- ---------------------------------------------------------------------------

Björn Peemöller 's avatar
Björn Peemöller committed
370 371
-- |
qualifyEnv :: Options -> CompilerEnv -> CompilerEnv
372
qualifyEnv opts env = expandValueEnv opts
Björn Peemöller 's avatar
Björn Peemöller committed
373 374 375 376 377 378
                    $ qualifyLocal env
                    $ foldl (flip importInterfaceIntf) initEnv
                    $ Map.elems
                    $ interfaceEnv env
  where initEnv = initCompilerEnv $ moduleIdent env

Björn Peemöller 's avatar
Björn Peemöller committed
379 380 381 382 383 384 385 386 387 388
qualifyLocal :: CompilerEnv -> CompilerEnv -> CompilerEnv
qualifyLocal currentEnv initEnv = currentEnv
  { opPrecEnv = foldr bindQual   pEnv  $ localBindings $ opPrecEnv currentEnv
  , tyConsEnv = foldr bindQual   tcEnv $ localBindings $ tyConsEnv currentEnv
  , valueEnv  = foldr bindGlobal tyEnv $ localBindings $ valueEnv  currentEnv
  }
  where
    pEnv  = opPrecEnv initEnv
    tcEnv = tyConsEnv initEnv
    tyEnv = valueEnv  initEnv
389
    bindQual   (_, y) = qualBindTopEnv "Modules.qualifyEnv" (origName y) y
Björn Peemöller 's avatar
Björn Peemöller committed
390 391
    bindGlobal (x, y)
      | uniqueId x == 0 = bindQual (x, y)
392
      | otherwise       = bindTopEnv "Modules.qualifyEnv" x y
Björn Peemöller 's avatar
Björn Peemöller committed
393 394 395 396 397 398 399 400

-- Importing an interface into another interface is somewhat simpler
-- because all entities are imported into the environment. In addition,
-- only a qualified import is necessary. Note that the hidden data types
-- are imported as well because they may be used in type expressions in
-- an interface.

importInterfaceIntf :: Interface -> CompilerEnv -> CompilerEnv
401
importInterfaceIntf i@(Interface m _ _) env = env
Björn Peemöller 's avatar
Björn Peemöller committed
402 403 404 405
  { opPrecEnv = importEntities m True (const True) id mPEnv  $ opPrecEnv env
  , tyConsEnv = importEntities m True (const True) id mTCEnv $ tyConsEnv env
  , valueEnv  = importEntities m True (const True) id mTyEnv $ valueEnv  env
  }
Björn Peemöller 's avatar
Björn Peemöller committed
406 407 408 409
  where
  mPEnv  = intfEnv bindPrec       i -- all operator precedences
  mTCEnv = intfEnv bindTCHidden   i -- all type constructors
  mTyEnv = intfEnv bindTy         i -- all values
Björn Peemöller 's avatar
Björn Peemöller committed
410 411 412

-- Error messages:

413 414
errUndefinedEntity :: ModuleIdent -> Ident -> Message
errUndefinedEntity m x = posErr x $
Björn Peemöller 's avatar
Björn Peemöller committed
415 416
  "Module " ++ moduleName m ++ " does not export " ++ name x

417 418
errUndefinedDataConstr :: Ident -> Ident -> Message
errUndefinedDataConstr tc c = posErr c $
Björn Peemöller 's avatar
Björn Peemöller committed
419 420
  name c ++ " is not a data constructor of type " ++ name tc

421 422 423 424
errUndefinedLabel :: Ident -> Ident -> Message
errUndefinedLabel tc c = posErr c $
  name c ++ " is not a label of record type " ++ name tc

425 426
errNonDataType :: Ident -> Message
errNonDataType tc = posErr tc $ name tc ++ " is not a data type"
Björn Peemöller 's avatar
Björn Peemöller committed
427

428 429
errImportDataConstr :: ModuleIdent -> Ident -> Message
errImportDataConstr _ c = posErr c $
Björn Peemöller 's avatar
Björn Peemöller committed
430
  "Explicit import for data constructor " ++ name c