@@ -46,11 +46,14 @@ implementations of the function for a specific type. For example, the
46 Idris> show (S (S (S Z)))
46 Idris> show (S (S (S Z)))
47 "sssZ" : String
47 "sssZ" : String
49−Only one instance of a class can be given for a type — instances may not
49+Only one instance of a class can be given for a type — instances may
50−overlap. Instance declarations can themselves have constraints. For
50+not overlap. Instance declarations can themselves have constraints.
51+To help with resolution, the arguments of an instance must be
52+constructors (either data or type constructors), variables or
53+constants (i.e. you cannot give an instance for a function). For
51−example, to define a ``Show`` instance for vectors, we need to know that
54+example, to define a ``Show`` instance for vectors, we need to know
52−there is a ``Show`` instance for the element type, because we are going
55+that there is a ``Show`` instance for the element type, because we are
53−to use it to convert each element to a ``String``:
56+going to use it to convert each element to a ``String``:
55.. code-block:: idris
58.. code-block:: idris
@@ -487,6 +490,25 @@ instance ``myord`` as follows, at the ``Idris`` prompt:
487 "[ssssO, sssO, sO]" : String
490 "[ssssO, sssO, sO]" : String
493+Determining Parameters
494+----------------------
496+When a class has more than one parameter, it can help resolution if
497+the parameters used to resolve the type class are restricted. For
500+.. code-block:: idris
502+ class Monad m => MonadState s (m : Type -> Type) | m where
506+In this class, only ``m`` needs to be known to resolve this class, and
507+``s`` can then be determined from the instance. This is declared with
508+the ``| m`` after the class declaration. We call ``m`` a *determining
509+parameter* of the ``MonadState`` class, because it is the parameter
510+used to resolve an instance.
491.. [1] Conor Mcbride and Ross Paterson. 2008. Applicative programming
513.. [1] Conor Mcbride and Ross Paterson. 2008. Applicative programming
492 with effects. J. Funct. Program. 18, 1 (January 2008),
514 with effects. J. Funct. Program. 18, 1 (January 2008),