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 7, 2024
1 parent 2dc4daf commit ea089d4
Show file tree
Hide file tree
Showing 2 changed files with 35 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
30 changes: 30 additions & 0 deletions lib/launcher/src/Data/MaybeK.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE DeriveFunctor #-}

module Data.MaybeK
( MaybeK (..)
, IsMaybe (..)
, maybeFromMaybeK
)
where

import Prelude

-- | A type level tag to indicate whether a value is present or not.
data IsMaybe = IsJust | IsNothing

-- | A Maybe carring the type level tag.
data MaybeK k a where
NothingK :: MaybeK IsNothing a
JustK :: a -> MaybeK IsJust a

deriving instance Show a => Show (MaybeK k a)
deriving instance Eq a => Eq (MaybeK k a)
deriving instance Functor (MaybeK k)

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

0 comments on commit ea089d4

Please sign in to comment.