Skip to content

Commit

Permalink
Add MaybeK type in the launcher lib
Browse files Browse the repository at this point in the history
  • Loading branch information
paolino committed May 3, 2024
1 parent 25ec94d commit 2436f12
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/launcher/cardano-wallet-launcher.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ library
hs-source-dirs:
src
exposed-modules:
Cardano.Launcher
, Cardano.Launcher.Node
Cardano.Launcher.Wallet
, Cardano.Startup
Cardano.Launcher
Cardano.Launcher.Node
Cardano.Launcher.Wallet
Cardano.Startup
Data.MaybeK
if os(windows)
build-depends: Win32
other-modules: Cardano.Startup.Windows
Expand Down
34 changes: 34 additions & 0 deletions lib/launcher/src/Data/MaybeK.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE StandaloneDeriving #-}

module Data.MaybeK
( MaybeK (..)
, Presence (..)
, fmapMaybeK
, maybeOfMaybeK
)
where

import Prelude

-- | A type level tag to indicate whether a value is present or not.
data Presence = Present | Absent

-- | A Maybe carring the type level tag.
data MaybeK x a where
NothingK :: MaybeK x Absent
JustK :: x -> MaybeK x Present

deriving instance Show x => Show (MaybeK x a)
deriving instance Eq x => Eq (MaybeK x a)

-- | Map a function over a MaybeK.
fmapMaybeK :: (x -> y) -> MaybeK x a -> MaybeK y a
fmapMaybeK _ NothingK = NothingK
fmapMaybeK f (JustK x) = JustK (f x)

-- | Convert a MaybeK to a Maybe, dropping the type level tag.
maybeOfMaybeK :: MaybeK x a -> Maybe x
maybeOfMaybeK NothingK = Nothing
maybeOfMaybeK (JustK x) = Just x

0 comments on commit 2436f12

Please sign in to comment.