Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A generic version of Data.Maybe
Haskell
branch: master
Failed to load latest commit information.
benchmarks
src/Data/Generics typo
tests oops forgot to add files
.ghci removed lens dependency
.gitignore Add CoreTest to .gitignore
.travis.yml get rid of stats thing from lens
CHANGES.txt change log added
HLint.hs first commit
LICENSE first commit
README.md typo
Setup.lhs first commit
generic-maybe.cabal version bump

README.md

Build Status

This module is a drop in replacement for 'Maybe'. It generalizes the functions to any types that share the same "sum of products" view of 'Maybe'.

To use the module for your type, enable GHC's DeriveGeneric extension and derive a Generic instance for your type.

{-# LANGUAGE DeriveGeneric #-}
import GHC.Generics

data Result a = Success a | Fail
    deriving (Show, Generic)

After which you can use the functions, like your type was 'Maybe'

λ> fromMaybe 'a' Fail
'a'
λ> fromMaybe 'a' $ Success 'b'
'b'
Something went wrong with that request. Please try again.