Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Haskell
Wiki community
Recent changes
Random page
HaskellWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Context alias
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Improvements === ==== “Context alias” instead of “class alias” ==== A “class alias” actually doesn’t stand for a class but for a context (or a part of a context). So it might be better to choose a slightly different syntax: context Foobar a = (Foo a, Bar a) However if we allow class "aliases" to be extended with new methods then a class "alias" is not just a name for a context. (It is actually a context with a new class) Maybe we should keep the syntax really light like: class Foobar a = (Foo a, Bar a) ==== Superclass constraints ==== John Meacham proposes the following syntax for class aliases (context aliases) with superclass constraints: class alias Num a = Eq a => (Additive a, Multiplicative a) This is not consistent with the superclass syntax of class declarations. I think, we should use this syntax: class alias Eq a => Num a = (Additive a, Multiplicative a) Or better: context Eq a => Num a = (Additive a, Multiplicative a) ==== Functional dependencies ==== Does the following make sense? class alias A a b = (B a b, C a b) | a -> b where ... ==== Associated data types and type synonyms ==== When <tt>{-# LANGUAGE TypeFamilies #-}</tt> is enabled, classes may declare [[GHC/Type_families|associated data types or associated type synonyms]]. If we allow class aliases to be extended with new methods, I think it make sense to also allow them to be extended with associated data types and type synonyms: class A a = (B a, C a) where type T a data D a ==== Equality constraints ==== When <tt>{-# LANGUAGE TypeFamilies #-}</tt> is enabled, type contexts can include [[GHC/Type_families#Equality_constraints|equality constraints]] (<tt>t1 ~ t2</tt>). It makes sense to also allow them in class aliases (context aliases) ==== Things to have in mind ==== In order to get the context alias extension well, we should have an eye on problems we might want to solve with the help of context aliases. Here are some: * <hask>MonadPlus</hask> should just be a combination of <hask>Alternative</hask> and <hask>Monad</hask> (actually, <hask>Alternative f</hask> should just be a combination of <hask>Applicative f</hask> and <hask>forall a. Monoid (f a)</hask>) * <hask>Applicative</hask> should be a superclass of <hask>Monad</hask>
Summary:
Please note that all contributions to HaskellWiki are considered to be released under simple permissive license (see
HaskellWiki:Copyrights
for details). If you don't want your writing to be edited mercilessly and redistributed at will, then don't submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
DO NOT SUBMIT COPYRIGHTED WORK WITHOUT PERMISSION!
Cancel
Editing help
(opens in new window)
Toggle limited content width