Skip to content


Subversion checkout URL

You can clone with
Download ZIP
A generic version of Data.Maybe
branch: master
Failed to load latest commit information.
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 typo
Setup.lhs first commit
generic-maybe.cabal version bump

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
λ> fromMaybe 'a' $ Success 'b'
Something went wrong with that request. Please try again.