Skip to content

Instantly share code, notes, and snippets.

@shlevy
Created April 7, 2018 22:58
Show Gist options
  • Save shlevy/965955a5b7873e269ac845615f3e3d77 to your computer and use it in GitHub Desktop.
Save shlevy/965955a5b7873e269ac845615f3e3d77 to your computer and use it in GitHub Desktop.
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeApplications #-}
module Test where
newtype Value a = Value a
class MaybeHasValue x where
maybeValue :: Maybe (Value x)
data Void
instance MaybeHasValue Void where
maybeValue = Nothing
instance MaybeHasValue () where
maybeValue = Just (Value ())
foo :: forall a . MaybeHasValue a => Maybe (Value a)
foo = maybeValue
bar :: (forall a . MaybeHasValue a => Value a) -> Void
bar f = case f of
Value x -> x
baz :: (forall a . MaybeHasValue a => Maybe (Value a)) -> Maybe Void
baz f = case f @() of
Just v -> Just $ bar v
Nothing -> Nothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment