Skip to content

Instantly share code, notes, and snippets.

@ramirez7
Created December 2, 2022 22:15
Show Gist options
  • Select an option

  • Save ramirez7/60aa92aa8e0e1f368e0e6bef69bc2591 to your computer and use it in GitHub Desktop.

Select an option

Save ramirez7/60aa92aa8e0e1f368e0e6bef69bc2591 to your computer and use it in GitHub Desktop.
Using ImplicitParams to guide type inference
-- asks is frequently too ambiguous
impAsks
:: forall a b es
. (?impReader :: Proxy a)
=> Reader a :> es
=> (a -> b)
-> Eff es a
impAsks = asks
withImpReader
:: forall a k
. (?impReader :: Proxy a => k)
-> k
withImpReader k = let ?impReader = Proxy @a in k
-- This example contains usage of 'asks' that would
-- normally be ambiguous but are not due to the implicit param
example :: Eff '[Reader Int, Reader String] Int
example =
withImpReader @Int $ do
x <- impAsks (+1)
withImpReader @String $ do
s <- impAsks (++ "hello world")
pure (x + length s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment