mirror of
https://github.com/sdiehl/write-you-a-haskell.git
synced 2024-10-03 22:38:04 +03:00
Merge pull request #94 from thomwiggers/master
Use name instead of Var as type for variable names
This commit is contained in:
commit
ae73485e04
@ -208,11 +208,11 @@ Context
|
||||
|
||||
The typing context or environment is the central container around which all
|
||||
information during the inference process is stored and queried. In Haskell our
|
||||
implementation will simply be a newtype wrapper around a Map of ``Var`` to
|
||||
implementation will simply be a newtype wrapper around a Map of ``Name`` to
|
||||
``Scheme`` types.
|
||||
|
||||
```haskell
|
||||
newtype TypeEnv = TypeEnv (Map.Map Var Scheme)
|
||||
newtype TypeEnv = TypeEnv (Map.Map Name Scheme)
|
||||
```
|
||||
|
||||
The two primary operations are *extension* and *restriction* which introduce or
|
||||
@ -230,7 +230,7 @@ Operations over the context are simply the usual Set operations on the
|
||||
underlying map.
|
||||
|
||||
```haskell
|
||||
extend :: TypeEnv -> (Var, Scheme) -> TypeEnv
|
||||
extend :: TypeEnv -> (Name, Scheme) -> TypeEnv
|
||||
extend (TypeEnv env) (x, s) = TypeEnv $ Map.insert x s env
|
||||
```
|
||||
|
||||
@ -648,11 +648,11 @@ context.
|
||||
Var x -> lookupEnv env x
|
||||
```
|
||||
|
||||
The function ``lookupVar`` looks up the local variable reference in typing
|
||||
The function ``lookupEnv`` looks up the local variable reference in typing
|
||||
environment and if found it instantiates a fresh copy.
|
||||
|
||||
```haskell
|
||||
lookupEnv :: TypeEnv -> Var -> Infer (Subst, Type)
|
||||
lookupEnv :: TypeEnv -> Name -> Infer (Subst, Type)
|
||||
lookupEnv (TypeEnv env) x = do
|
||||
case Map.lookup x env of
|
||||
Nothing -> throwError $ UnboundVariable (show x)
|
||||
|
Loading…
Reference in New Issue
Block a user