| | 19 | |
| | 20 | If we encounter an instance declaration for `C tau` during conversion, there are two alternatives: we have a conversion for `C` or not: |
| | 21 | * if we do not have a conversion, we generate an instance (and hence dfun) for `C tau^`, where `tau^` is the closure converted `tau`; |
| | 22 | * if we have a conversion, we generate an instance for `C_CC tau^`. |
| | 23 | In any case, we add a field `is_CC :: Just Instance` to `InstEnv.Instance` that contains the additionally generated instance. And in both cases, we should be able to derive the required code for the dfun from the definition of `C tau`. |
| | 24 | |
| | 25 | === Type terms === |
| | 26 | |
| | 27 | We determine the converted type `t^` of `t` as follows: |
| | 28 | {{{ |
| | 29 | T^ = T_CC , if available |
| | 30 | T , otherwise |
| | 31 | a^ = a |
| | 32 | (t1 t2)^ = t1^ t2^ |
| | 33 | (t1 -> t2)^ = Clo t1 t2 |
| | 34 | (forall a.t)^ = forall a.t^ |
| | 35 | (C t1 => t2)^ = C_CC t1^ => t2^ , if available |
| | 36 | C t1^ => t2^ , otherwise |
| | 37 | }}} |
| | 38 | |
| | 39 | === Value bindings === |
| | 40 | |
| | 41 | When converting a toplevel binding for `f :: t`, we generate `f_CC :: t^`. The alternatives `GlobalId` and `LocalId` of `Var.Var` get a new field `idCC :: Maybe Id` and the `Id` for `f` contains `Just f_CC` in that field. |