-
Notifications
You must be signed in to change notification settings - Fork 643
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This allows code like: data Identity i = Id i class Functor (f : Type -> Type) where map : (a -> b) -> f a -> f b class Functor f => Applicative (f : Type -> Type) where instance Functor f where map f fa = ap (pure f) fa pure : a -> f a ap : f (a -> b) -> f a -> f b instance Applicative Identity where pure = Id ap (Id f) (Id a) = Id (f a) data Nat = Z | S Nat x : Identity Nat x = map S (Id Z) Note the default Functor instance defined as part of the Applicative class. This allows the Identity data type to omit an explicit Functor instance and one gets defined from the Applicative instance. This feature is largely copied from the approach done in She: https://personal.cis.strath.ac.uk/conor.mcbride/pub/she/superclass.html It basically does macro expansion of each default superclass instance (e.g. Functor) when the containing class (e.g. Applicative) gets an instance defined. Currently, default superclass instance definitions are not type-checked, only their macro expansions are. Default superclass instances are limited to being defined for types which are syntactically equal to one of the superclass constraints.
- Loading branch information
1 parent
2f52264
commit 99beed8
Showing
8 changed files
with
109 additions
and
55 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