-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add type vars and parse them * Before we have a bad time * Good lad * Nice * Damn, some sort of polymorphism * Failing test for using non-boxed generic type{ * Only pass boxed types to polymorphic functions * Check return type * Unbox operator * Fix linties
- Loading branch information
1 parent
0ccb6a8
commit ba4f068
Showing
31 changed files
with
820 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,44 @@ | ||
module Calc.TypeUtils (mapOuterTypeAnnotation, getOuterTypeAnnotation) where | ||
module Calc.TypeUtils | ||
( bindType, | ||
mapType, | ||
mapOuterTypeAnnotation, | ||
getOuterTypeAnnotation, | ||
) | ||
where | ||
|
||
import Calc.Types.Type | ||
import Control.Monad.Identity | ||
|
||
getOuterTypeAnnotation :: Type ann -> ann | ||
getOuterTypeAnnotation (TPrim ann _) = ann | ||
getOuterTypeAnnotation (TFunction ann _ _) = ann | ||
getOuterTypeAnnotation (TTuple ann _ _) = ann | ||
getOuterTypeAnnotation (TContainer ann _) = ann | ||
getOuterTypeAnnotation (TVar ann _) = ann | ||
getOuterTypeAnnotation (TUnificationVar ann _) = ann | ||
|
||
mapOuterTypeAnnotation :: (ann -> ann) -> Type ann -> Type ann | ||
mapOuterTypeAnnotation f (TPrim ann p) = TPrim (f ann) p | ||
mapOuterTypeAnnotation f (TFunction ann a b) = TFunction (f ann) a b | ||
mapOuterTypeAnnotation f (TTuple ann a b) = TTuple (f ann) a b | ||
mapOuterTypeAnnotation f (TContainer ann a) = TContainer (f ann) a | ||
mapOuterTypeAnnotation f (TVar ann v) = TVar (f ann) v | ||
mapOuterTypeAnnotation f (TUnificationVar ann v) = TUnificationVar (f ann) v | ||
|
||
mapType :: (Type ann -> Type ann) -> Type ann -> Type ann | ||
mapType f ty = | ||
runIdentity (bindType (pure . f) ty) | ||
|
||
bindType :: | ||
(Applicative m) => | ||
(Type ann -> m (Type ann)) -> | ||
Type ann -> | ||
m (Type ann) | ||
bindType _ (TPrim ann p) = | ||
pure $ TPrim ann p | ||
bindType f (TFunction ann a b) = | ||
TFunction ann <$> traverse f a <*> f b | ||
bindType f (TContainer ann as) = | ||
TContainer ann <$> traverse f as | ||
bindType _ (TVar ann a) = | ||
pure $ TVar ann a | ||
bindType _ (TUnificationVar ann a) = | ||
pure $ TUnificationVar ann a |
Oops, something went wrong.