Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
research:software:haskellaop:ghc-extensions [2012/09/26 20:27] – [GHC Type Extensions] ifigueroresearch:software:haskellaop:ghc-extensions [2012/12/06 12:57] (current) – [MultiParamTypeClasses] ifiguero
Line 1: Line 1:
 ====== GHC Type Extensions ====== ====== GHC Type Extensions ======
-This is a brief introduction to the GHC Haskell type system extensions used in our implementation, with pointers to the relevant documentation.+This is a brief introduction to the GHC Haskell type system extensions used in [[http://pleiad.dcc.uchile.cl/research/software/haskellaop|our implementation of pointcut-advice AOP in Haskell]], with pointers to the relevant documentation.
 ==== ScopedTypeVariables ==== ==== ScopedTypeVariables ====
 This extension allows free type variables (in the type signature of the function) to be re-used in the scope of a function. For examples and more documentation, see [[http://www.haskell.org/haskellwiki/Scoped_type_variables|here]]. This extension allows free type variables (in the type signature of the function) to be re-used in the scope of a function. For examples and more documentation, see [[http://www.haskell.org/haskellwiki/Scoped_type_variables|here]].
Line 8: Line 8:
 By default, type classes in Haskell can only have one type parameter. This extension allows a type class to take one or more arguments, thus becoming a relation between types.  By default, type classes in Haskell can only have one type parameter. This extension allows a type class to take one or more arguments, thus becoming a relation between types. 
  
-The standard monadic libraries depend on this extension. For instance, the MonadState is parameterized by the state type s, and the monad, and implies that in m one can manipulate a state of type s using the get and put operations [[http://hackage.haskell.org/packages/archive/mtl/latest/doc/html/Control-Monad-State-Class.html|Ref.]]+The standard monadic libraries depend on this extension. For instance, the MonadState is parameterized by the state type s, and the monad m, and implies that in m one can manipulate a state of type s using the get and put operations [[http://hackage.haskell.org/packages/archive/mtl/latest/doc/html/Control-Monad-State-Class.html|See Reference.]]
  
-We use this extension to define three multi-parameter type classes: +We use this extension to define the following multi-parameter type classes: 
- * OpenApp, for overloaded uses of #. +  * OpenApp, for overloaded uses of #. 
- * MonadDeploy, to specify the semantics of aspect deployment. +  * MonadDeploy, to specify the semantics of aspect deployment. 
- * LeastGen', LeastGen, and LessGen,which define the anti-unification algorithm.+  * LeastGen', LeastGen, and LessGen,which define the anti-unification algorithm.
  
 Multi-parameter type classes can introduce ambiguity in type inference, and are usually used in conjunction with the FunctionalDependencies extension [[http://hackage.haskell.org/trac/haskell-prime/wiki/MultiParamTypeClassesDilemma| see here for a detailed discussion]]. Multi-parameter type classes can introduce ambiguity in type inference, and are usually used in conjunction with the FunctionalDependencies extension [[http://hackage.haskell.org/trac/haskell-prime/wiki/MultiParamTypeClassesDilemma| see here for a detailed discussion]].
  
 ==== FunctionalDependencies ==== ==== FunctionalDependencies ====
-Multi-parameter typeclasses can introduce ambiguities that prevent type inference from deducing a type. Functional dependencies are a mechanism to more precisely control type inference. A functional dependency states that one of the parameters of a type class can be uniquely determined from the values of other parameters. [[http://www.haskell.org/haskellwiki/Functional_dependencies|Ref.]] We use this extension to define the typeclasses for our anti-unification algorithm.+Multi-parameter typeclasses can introduce ambiguities that prevent type inference from deducing a type. Functional dependencies are a mechanism to more precisely control type inference. A functional dependency states that one of the parameters of a type class can be uniquely determined from the values of other parameters. We use this extension to define the typeclasses for our anti-unification algorithm. [[http://www.haskell.org/haskellwiki/Functional_dependencies|See Reference.]] 
  
 ==== FlexibleInstances ==== ==== FlexibleInstances ====
-In Haskell 98, the form of an instance declaration is restricted to a type constructor applied to zero or more different type variables. This extension relaxes the form of instances, and is pervasively used in the standard monad library. We use it mainly for integration with this library [[http://hackage.haskell.org/trac/haskell-prime/wiki/FlexibleInstances|Ref.]]+In Haskell 98, the form of an instance declaration is restricted to a type constructor applied to zero or more different type variables. This extension relaxes the form of instances, and is pervasively used in the standard monad library. We use it mainly for integration with this library [[http://hackage.haskell.org/trac/haskell-prime/wiki/FlexibleInstances|See Reference.]]
  
 ==== FlexibleContexts ==== ==== FlexibleContexts ====
-This extension relaxes the form of the contexts of type signatures, newtype, and data declarations. It is usually used in conjunction with MultiParamTypeClasses and FlexibleInstances [[Ref|http://hackage.haskell.org/trac/haskell-prime/wiki/FlexibleContexts]].+This extension relaxes the form of the contexts of type signatures, newtype, and data declarations. It is usually used in conjunction with MultiParamTypeClasses and FlexibleInstances [[http://hackage.haskell.org/trac/haskell-prime/wiki/FlexibleContexts|See Reference.]]
  
 ==== TemplateHaskell ==== ==== TemplateHaskell ====
-This language extension allows the use of TemplateHaskell in a module [[Ref|http://www.haskell.org/ghc/docs/latest/html/users_guide/template-haskell.html]].+This language extension allows the use of TemplateHaskell in a module. It is necessary to use our macro expansions for advising bounded polymorphic functions. [[http://www.haskell.org/ghc/docs/latest/html/users_guide/template-haskell.html|See Reference.]]
  
-==== TypeSynonimInstances ==== +==== TypeSynonymInstances ==== 
-Instance declarations only allow type constructors defined using data or newtype. This extension allows to use type synonyms in instance declarations. This extension is used mainly for convenience, since type synonyms are just textual replacements performed in the compilation process. This extension is used typically with FlexibleInstances or UndecidableInstances [[http://hackage.haskell.org/trac/haskell-prime/wiki/TypeSynonymInstances|Ref]].+Instance declarations only allow type constructors defined using data or newtype. This extension allows to use type synonyms in instance declarations. This extension is used mainly for convenience, since type synonyms are just textual replacements performed in the compilation process. This extension is used typically with FlexibleInstances or UndecidableInstances [[http://hackage.haskell.org/trac/haskell-prime/wiki/TypeSynonymInstances|See Reference.]]
  
 ==== DeriveDataTypeable ==== ==== DeriveDataTypeable ====
-When defining a type using data, a "deriving" clause is used to specify that this type is automatically declared as instance of some type classes. By default, a type can only automatically derive the standard classes Eq, Ord, Enum, Ix, Bounded, Read, and Show. This extension allows to derive the Typeable and Data types. We use it to automatically derive Typeable instances, since our approach is based on PolyTypeable, which extends Typeable. [[http://www.haskell.org/ghc/docs/7.4.2/html/users_guide/deriving.html|Ref]]+When defining a type using data, a "deriving" clause is used to specify that this type is automatically declared as instance of some type classes. By default, a type can only automatically derive the standard classes Eq, Ord, Enum, Ix, Bounded, Read, and Show. This extension allows to derive the Typeable and Data types. We use it to automatically derive Typeable instances, since our approach is based on PolyTypeable, which extends Typeable. [[http://www.haskell.org/ghc/docs/7.4.2/html/users_guide/deriving.html|See Reference.]]
  
 ==== GeneralizedNewtypeDeriving ==== ==== GeneralizedNewtypeDeriving ====
Line 41: Line 41:
  
 ==== KindSignatures ==== ==== KindSignatures ====
-As types are assigned to values, when using type variables it can be necessary to distinguish the arity of type constructors. Haskell by default assigns //kinds// to types, and uses this information during typechecking. This extension allows the programmer to explicitly state the kind of type arguments. A nullary kind is denoted *, that is, a type constructor with arity 0, like Int or Float. A unary kind is denoted (* -> *) and so on. [[http://www.haskell.org/ghc/docs/latest/html/users_guide/other-type-extensions.html| Ref]], [[http://stackoverflow.com/questions/9857553/kind-signatures|Ref2]].+As types are assigned to values, when using type variables it can be necessary to distinguish the arity of type constructors. Haskell by default assigns //kinds// to types, and uses this information during typechecking. This extension allows the programmer to explicitly state the kind of type arguments. A nullary kind is denoted *, that is, a type constructor with arity 0, like Int or Float. A unary kind is denoted (* -> *) and so on. [[http://www.haskell.org/ghc/docs/latest/html/users_guide/other-type-extensions.html|See Reference 1]], [[http://stackoverflow.com/questions/9857553/kind-signatures|See Reference 2]].
  
 ==== ConstraintKinds ==== ==== ConstraintKinds ====
Line 57: Line 57:
 RankN types are related to existential quantification because the only way to //unpack// an existential type is to use a function that works on **any** type that could be stored in the existential. RankN types are related to existential quantification because the only way to //unpack// an existential type is to use a function that works on **any** type that could be stored in the existential.
  
-We use this extensions to express the parametricity property of the non-interfering aspects, pointcuts and advices. [[http://www.haskell.org/haskellwiki/Rank-N_types|Ref]].+We use this extensions to express the parametricity property of the non-interfering aspects, pointcuts and advices. [[http://www.haskell.org/haskellwiki/Rank-N_types|See Reference.]] 
 ==== ImpredicativeTypes ==== ==== ImpredicativeTypes ====
-This extension allows to call a polymorphic function at a polymorphic type, and parameterise data structures over polymorphic types. [[http://www.haskell.org/ghc/docs/latest/html/users_guide/other-type-extensions.html|Ref.]]+This extension allows to call a polymorphic function at a polymorphic type, and parameterise data structures over polymorphic types. [[http://www.haskell.org/ghc/docs/latest/html/users_guide/other-type-extensions.html|See Reference.]]
  
 ==== OverlappingInstances and IncoherentInstances ==== ==== OverlappingInstances and IncoherentInstances ====
Line 66: Line 67:
 Using OverlappingInstances, instances are allowed to overlap as long as there is a most specific one in any case. An instance X is more specific than an instance Y if X could match Y, but not vice versa. However in certain cases, the compiler cannot commit to one instance because the most specific one can be different in different applications of a function. For these cases, using IncoherentInstances tells GHC to arbitrarily pick one of these instances. Using OverlappingInstances, instances are allowed to overlap as long as there is a most specific one in any case. An instance X is more specific than an instance Y if X could match Y, but not vice versa. However in certain cases, the compiler cannot commit to one instance because the most specific one can be different in different applications of a function. For these cases, using IncoherentInstances tells GHC to arbitrarily pick one of these instances.
  
-We use these extensions, along with UndecidableInstances to the anti-unification algorithm using type classes. These three extensions are also used in the standard monad library.+We use these extensions, along with UndecidableInstances in the implementation of the anti-unification algorithm using type classes. These three extensions are also used in the standard monad library. 
 + 
 +[[http://hackage.haskell.org/trac/haskell-prime/wiki/OverlappingInstances| See Reference on OverlappingInstances.]] 
 +[[http://www.haskell.org/ghc/docs/6.6/html/users_guide/type-extensions.html| See Reference on IncoherentInstances.]]
  
 ==== UndecidableInstances ==== ==== UndecidableInstances ====
-This extension is a more powerful version of FlexibleInstances. When enabled, there are no restrictions on the form of instance declarations. It is up to implementors to ensure that constraint resolution works. [[http://hackage.haskell.org/trac/haskell-prime/wiki/UndecidableInstances|Ref]]+This extension is a more powerful version of FlexibleInstances. When enabled, there are no restrictions on the form of instance declarations. It is up to implementors to ensure that constraint resolution works. [[http://hackage.haskell.org/trac/haskell-prime/wiki/UndecidableInstances|See Reference.]]
  
  
 ==== TypeFamilies ==== ==== TypeFamilies ====
-This extension allows ad-hoc overloading of data types. That is, types families are parametric types that can be assigned specialized representations based on the type parameters they are instantiated with. They are the type analogue of type classes, used for function overloading according to the types of the arguments.+This extension allows ad-hoc overloading of data types. That is, types families are parametric types that can be assigned specialized representations based on the type parameters they are instantiated with. They are the type analogue of type classes, used for function overloading according to the types of the arguments. [[http://www.haskell.org/ghc/docs/7.2.2/html/users_guide/type-families.html|See Reference.]]
  
 We use this extension to implement our anti-unification typeclass, and also to define a typeclass for the pcAnd pointcut combinator. In this type class, each instance can use a different context, using also the ConstraintKinds extension. We use this extension to implement our anti-unification typeclass, and also to define a typeclass for the pcAnd pointcut combinator. In this type class, each instance can use a different context, using also the ConstraintKinds extension.
Line 81: Line 85:
 Lifting the MR means that all bindings are polymorphic unless constrained by a type signature. A good discussion on the MR can be found [[http://www.haskell.org/haskellwiki/Monomorphism_restriction|here]]. Lifting the MR means that all bindings are polymorphic unless constrained by a type signature. A good discussion on the MR can be found [[http://www.haskell.org/haskellwiki/Monomorphism_restriction|here]].
  
-We use this extension in some examples to decrease the quantity of type annotations. In general, the influence of the MR during typechecker can be avoided by using explicit type signatures.+We use this extension in some examples to decrease the quantity of type annotations. In general, the influence of the MR during typechecking can be avoided by using explicit type signatures.