yesodweb / yesodweb/persistent

Deriving Typeclasses with Arguments

Open
#1,405 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Haskell
Stars
486
Forks
306
PR merge metrics
No merged PRs in 30d

Description

Version: 2.14.0.0
Stack LTS: 19.5

Take the following typeclass:

class Pointless a b where
    lol :: a -> b -> ()
    lol = const $ const ()

This could be derived as follows:

data Something = Something
    { a :: Int
    , b :: Int
    } deriving (Pointless Int)

However the following fails as a persistent template:

Person
    name String
    age Int
    deriving Show (Pointless Int)

The error given is Illegal type constructor or class name: ‘Pointless Int’.

And the deriving statements appear to be expanded to:

    deriving stock Show
    deriving anyclass Pointless Int

I assume it's due to the omission of the brackets in the generated code? Is there a way I can get persistent to keep them, is this a bug or just not something that is supported?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the persistent template expansion that emits the deriving clauses, then compare the source deriving (Pointless Int) with generated deriving anyclass Pointless Int. Done means either generated Haskell preserves the parentheses and compiles, or the issue is documented as unsupported.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
database, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.