Skip to content

MarcelineVQ/idris2-newtype-deriving

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Newtype, Generic Interface Deriving

This package provides sorely-missed deriving for common interfaces like Num for newtypes and newtype-likes, iow single-constructor types. For instance:

import Generics.Newtype
%language ElabReflection

data Raf = MkRaf Double
%runElab derive "Raf"
  [Generic, Eq, Ord, Num, Neg, Abs, Fractional, FromDouble]

data Raff a b = MkRaff a b
%runElab derive "Raff"
  [Generic, Eq, Ord, Num, Neg, Abs, Fractional, FromDouble, Integral]

Your projects using this lib need to depend on sop and elab-util.

Code here is based on the pristine work done by Stefan Hoeck.

This package could be improved by scanning interfaces and generating the implementations programmaticlly but it does not do so currently and the deriving machinery is instead assembled by hand.

Version

This package follows Haskell PVP which is distinct from SEMVER in that when examining 1.2.3, 1.2 is the Major Version rather than 1.