Skip to content

Instantly share code, notes, and snippets.

@epost
Created January 24, 2015 15:53
Show Gist options
  • Save epost/e5f8731c72d33c95a1b8 to your computer and use it in GitHub Desktop.
Save epost/e5f8731c72d33c95a1b8 to your computer and use it in GitHub Desktop.
ContT inference question
-- Some code excerpts to illustrate the following question:
-- Why is the type ascription
--
-- :: forall eff. ContT _ _ [F Number]
--
-- below necessary? Why isn't `[F a]` inferred to be `[F Number]` from
-- our use of `:: Query a` in the call to `runQueryCont`?
-- My assumption: choosing a `Query a` fixes `a` as well as the `[F a]` in the result type
runQueryCont :: forall eff a rxx. (IsForeign a) => Query a -> Client -> ContT rxx (DBEff eff) [F a]
runQueryCont query client = ContT $ runQuery query client
main =
runContT
(withConnection $ \con -> do
ns <- (
-- Here, we instantiate `a` at `Number`, by our ascription `:: Query Number`,
-- which I assumed would make the explicit `:: forall eff. ContT _ _ [F Number]` unnecessary.
(runQueryCont ("insert into artist values ('Deep Purple', 1968) returning year as result" :: Query Number) con)
:: forall eff. ContT _ _ [F Number]
-- Omitting the type ascription [F Number] above causes a compile error.
-- Why is this, since `Query a` above fixes `a` and therefore `[F a]`?
)
lift $ printNumbers ns
runQueryCont ("select * from artist" :: Query Artist) c
)
printArtists
printNumbers :: forall eff. [F Number] -> Eff (trace :: Trace | eff) Unit
printNumbers xs = trace $ "numbers:\n" <> foldMap stringify xs
where stringify = show >>> flip (<>) "\n"
printArtists :: forall eff. [F Artist] -> Eff (trace :: Trace | eff) Unit
printArtists artists = trace $ "numbers:\n" <> foldMap stringify artists
where stringify = show >>> flip (<>) "\n"
@epost
Copy link
Author

epost commented Jan 24, 2015

For future reference: jutaro suggested on irc that this "might be a bug in the typechecker, see 810, 812, 814, ..." purescript/purescript#810, purescript/purescript#812, purescript/purescript#814

@epost
Copy link
Author

epost commented Feb 11, 2015

Problem turned out to be that Query was a type synonym instead of a proper type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment