haskell-servant / haskell-servant/haskell-servant.github.io

Code from 2018-07-12 doesn't typecheck.

Open
#59 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
18
Forks
21
PR merge metrics
No merged PRs in 30d

Description

The pretty instance for `Mul`:
```haskell
instance (Pretty l, Pretty r) => Pretty (Mul l r) where
pretty (Mul a b) = unwords [autoParens a, "*", autoParens b]
where autoParens a@(Add _ _) = "(" ++ pretty a ++ ")"
autoParens a = pretty a
```
Gives the following error:
```
• Couldn't match expected type ‘Add l0 r0’ with actual type ‘l’
‘l’ is a rigid type variable bound by
the instance declaration
at /home/leif/Documents/type-level/src/Lib.hs:91:10-49
• In the first argument of ‘autoParens’, namely ‘a’
In the expression: autoParens a
In the first argument of ‘unwords’, namely
‘[autoParens a, "*", autoParens b]’
• Relevant bindings include
a :: l (bound at /home/leif/Documents/type-level/src/Lib.hs:92:15)
pretty :: Mul l r -> String
(bound at /home/leif/Documents/type-level/src/Lib.hs:92:3)
```
And the same for `autoParens b`. I think I'm missing a LANGUAGE pragma somewhere that would prevent `autoParens (Add _ _)` from collapsing to `Add l r -> String`.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.