In Haskell 98, the allowed contexts are restricted, so contexts are reduced using `instance` declarations (and duplicate assertions and those implied by `class` contexts are removed) until either they are in the allowed form or no instance is applicable, in which case an error is reported. For example, in the following

21

{{{

22

module M where

23

class C a where c_method :: a -> Bool

24

foo xs = c_method (tail xs)

25

}}}

26

the context of the inferred type

27

{{{

28

foo :: C [a] => [a] -> Bool

29

}}}

30

is neither allowed nor reducible, so a missing instance `C [a]` is reported.

31

32

When contexts are unrestricted, context reduction is forced only by explicit signatures and the type of `main`.

33

The above example becomes legal; if a matching instance is in scope when context reduction is forced on uses of `foo`, they will also typecheck:

34

{{{

35

import M

36

instance C [a] where c_method = null

37

38

main :: IO ()

39

main = print (foo "abc")

40

}}}

41

42

Delaying context reduction:

43

* can leave contexts more complex (could interact with the Monomorphism Restriction)

44

* delays (and sometimes avoids) type errors

45

* sometimes avoids nontermination of context reduction

46

* is required by OverlappingInstances

47

17

48

== References ==

18

49

* [http://www.haskell.org/onlinereport/decls.html#sect4.1.3 Syntax of Class Assertions and Contexts] in the Haskell 98 Report