Skip to content
A generic version of Data.Maybe
Haskell
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
benchmarks
src/Data/Generics
tests
.ghci
.gitignore
.travis.yml
CHANGES.txt
HLint.hs
LICENSE
README.md
Setup.lhs
generic-maybe.cabal

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.