{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE StrictData #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE ScopedTypeVariables #-} module MaybeHelp where import Control.Lens import Data.Aeson import GHC.Generics import TH.Derive import Data.Store data Maybe' a = Just' {__Just' :: a} | Nothing' deriving (Eq,Ord,Show,Read,Generic) instance ToJSON a => ToJSON (Maybe' a) where toEncoding = genericToEncoding defaultOptions instance FromJSON a => FromJSON (Maybe' a) fromJust' :: Maybe' a -> a fromJust' mx = case mx of Just' x -> x Nothing' -> error "no fromJust'" isJust' :: Maybe' a -> Bool isJust' Just' {} = True isJust' Nothing' = False isNothing' :: Maybe' a -> Bool isNothing' Just' {} = False isNothing' Nothing' = True strictify :: Maybe a -> Maybe' a strictify Nothing = Nothing' strictify (Just x) = Just' x toggleJust :: Maybe a -> Maybe () toggleJust Nothing = Just () toggleJust _ = Nothing makeLenses ''Maybe' $($(derive [d| instance (Store a => Deriving (Store (Maybe' a))) |]))