generic-records-0.2.0.0: Magic record operations using generics

Copyright(C) 2017 Csongor Kiss
LicenseBSD3
MaintainerCsongor Kiss <kiss.csongor.kiss@gmail.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellSafe
LanguageHaskell2010

Records.Generic.Subtype

Description

Structural subtyping

Synopsis

Documentation

class Subtype sub sup where Source #

Structural subtype relationship

  module Test where

  import GHC.Generics
  import Record.Generic

  data Human = Human
    { name    :: String
    , age     :: Int
    , address :: String
    } deriving (Generic, Show)

  data Animal = Animal
    { name    :: String
    , age     :: Int
    } deriving (Generic, Show)

   human :: Human
   human = Human "Tunyasz" 50 "London"

>>> human
Human {name = "Tunyasz", age = 50, address = "London"}
>>> upcast human :: Animal
Animal {name = "Tunyasz", age = 50}

Minimal complete definition

upcast

Methods

upcast :: sub -> sup Source #

Cast the more specific subtype to the more general supertype

Instances

(Convert (Rep a) (Rep b), Generic a, Generic b) => Subtype a b Source #

Instances are created by the compiler

Methods

upcast :: a -> b Source #