overloaded-0.3.1: Overloaded pragmas as a plugin
Safe HaskellSafe-Inferred
LanguageHaskell2010

Overloaded.Constructors

Synopsis

Documentation

class HasConstructor x (s :: Type) (a :: Type) | x s -> a where Source #

Class for the overloaded constructors.

Instances for this class are automatically generated by type-checker plugin, but you may also defined your own. See an example instances for Either.

{-# OPTIONS -fplugin=Overloaded -fplugin-opt=Overloaded:Constructors #-}

Additionally, this overload steals syntax transforming all (:name arg1 arg2) into build @"name" (arg1, arg2) expressions. Parenthesis are important as standalone :name is (for now) not valid Haskell syntax and they also naturally delimit the arguments.

For nullary constructors the a type is unit (), for unary the type is used as is, and for others the parameters are wrapped into a tuple. The last case is not particularly pretty, but its overloadable.

Methods

build :: a -> s Source #

match :: s -> Maybe a Source #

Instances

Instances details
a' ~ a => HasConstructor "Left" (Either a b) a' Source # 
Instance details

Defined in Overloaded.Constructors

Methods

build :: a' -> Either a b Source #

match :: Either a b -> Maybe a' Source #

a' ~ b => HasConstructor "Right" (Either a b) a' Source # 
Instance details

Defined in Overloaded.Constructors

Methods

build :: a' -> Either a b Source #

match :: Either a b -> Maybe a' Source #