Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,842
    • Issues 4,842
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 454
    • Merge requests 454
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #20770

Closed
Open
Created Dec 02, 2021 by Icelandjack@IcelandjackReporter

Export Stock, Stock1 modifiers with virtual stock instances

I propose two newtypes in base to replace and generalize the stock deriving strategy

type    Stock :: Type -> Type
newtype Stock a = Stock a

type    Stock1 :: (k -> Type) -> (k -> Type)
newtype Stock1 f a = Stock1 (f a)

with magical compiler instances every time deriving stock Cls works then the instance for Cls (Stock a) or Cls (Stock1 f) should be generated, depending on the kind of Cls's argument. The purpose is to simplify deriving (Haskell Proposal: Simplify Deriving) and to make stock deriving first-class. I think we can soon derive Traversable :) so I will include it

type Medal :: Type
data Medal = Gold | Silver | Bronze
  deriving (Eq, Ord)
  via Stock Medal

type List :: Type
data List a = Nil | Cons a (List a)
  deriving (Functor, Foldable, Traversable)
  via Stock1 List

Them being "first-class" means they are now types like any other modifier and can be combined into more complicated behaviours, Down reverses the stock instance and Reverse reverses the order of processing to be right-to-left.

type Medal :: Type
data Medal = Bronze | Silver | Gold
  deriving (Eq, Ord)
  via Down (Stock Medal)

type Snoc :: Type
data Snoc a = Nil | Snoc (Snoc a) a
  deriving (Functor, Foldable, Traversable)
  via Reverse (Stock1 Snoc)
Edited Dec 02, 2021 by Icelandjack
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking