
27 Jan
2020
27 Jan
'20
9:35 p.m.
This compiles but I don't get the proper instance of the typeclass when I run it
You did not tell us to which concrete type M you instantiate the type variable m when you run your code. Your wording suggests that you may misunderstand how instantiation of type variables works: it is the caller of the debit function who chooses the M; in fact it can choose /any/ M, as long as it satisfies the listed constraints. If your code compiles but doesn't work, then the M your caller has chosen has a wrong instance that doesn't do what it should do. If it is not obvious from the calling code what the M is, try to use local type annotations with type holes, so the compiler tells you what the type is. Cheers Ben