Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
GHC
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
4,326
Issues
4,326
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
390
Merge Requests
390
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Glasgow Haskell Compiler
GHC
Commits
c4dd4ae7
Commit
c4dd4ae7
authored
Apr 28, 2016
by
Simon Peyton Jones
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better documentation of -XConstrainedClassMethods
parent
3dce4f2d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
10 deletions
+18
-10
docs/users_guide/glasgow_exts.rst
docs/users_guide/glasgow_exts.rst
+18
-10
No files found.
docs/users_guide/glasgow_exts.rst
View file @
c4dd4ae7
...
...
@@ -4551,23 +4551,31 @@ context.
.. _class-method-types:
Class method types
~~~~~~~~~~~~~~~~~~
C
onstrained c
lass method types
~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~
.. ghc-flag:: -XConstrainedClassMethods
Allows the definition of further constraints on individual class methods.
Haskell 98 prohibits class method types to mention constraints on the
class type variable, thus: ::
class Seq s a where
fromList :: [a] -> s a
elem :: Eq a => a -> s a -> Bool
@ -4562,7 +4562,20 @@ class type variable, thus: ::
The type of ``elem`` is illegal in Haskell 98, because it contains the
constraint ``Eq a``, which constrains only the class type variable (in
this case ``a``).
this case ``a``). More precisely, a constraint in a class method signature is rejected if
- The constraint mentions at least one type variable. So this is allowed: ::
class C a where
op1 :: HasCallStack => a -> a
op2 :: (?x::Int) => Int -> a
- All of the type variables mentioned are bound by the class declaration, and none is locally quantified. Examples: ::
class C a where
op3 :: Eq a => a -> a -- Rejected: constrains class variable only
op4 :: D b => a -> b -- Accepted: constrains a locally-quantified varible `b`
op5 :: D (a,b) => a -> b -- Accepted: constrains a locally-quantified varible `b`
GHC lifts this restriction with language extension
:ghc-flag:`-XConstrainedClassMethods`. The restriction is a pretty stupid one in
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment