Skip to content

Instantly share code, notes, and snippets.

@Porges
Created April 18, 2018 21:32
Show Gist options
  • Save Porges/b65eee73de15a5f19f548ca885351c95 to your computer and use it in GitHub Desktop.
Save Porges/b65eee73de15a5f19f548ca885351c95 to your computer and use it in GitHub Desktop.
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE ImplicitParams #-}
{- declaration -}
data MyModuleType =
MkMyModule
{ mod_global1 :: Int
, mod_global2 :: String
}
-- ConstraintKinds lets us write an alias
-- for the implicit param:
type MyModule = (?myModule :: MyModuleType)
-- accessors for 'global' values:
global1 :: MyModule => Int
global1 = mod_global1 ?myModule
global2 :: MyModule => String
global2 = mod_global2 ?myModule
{- usage -}
main =
-- instantiate module
let ?myModule = MkMyModule 123 "456" in
print whatever
-- function that uses module implicitly
whatever :: MyModule => String
whatever = show global1 ++ global2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment