Skip to content

Instantly share code, notes, and snippets.

@JordanMartinez
Created August 20, 2022 15:09
Show Gist options
  • Save JordanMartinez/54dac16b401126b30da5be7233471b7a to your computer and use it in GitHub Desktop.
Save JordanMartinez/54dac16b401126b30da5be7233471b7a to your computer and use it in GitHub Desktop.
Indexed Access Type - Dictionary Cost
module Main where
import Prelude
import Effect (Effect)
import Effect.Class.Console (log)
import TryPureScript as TryPureScript
import Prim.Row as Row
main :: Effect Unit
main = TryPureScript.render =<< TryPureScript.withConsole do
log "some value"
-- Common boilerplate:
class Accessory :: Type -> Symbol -> Type -> Constraint
class Accessory r s t | r s -> t
type Access r s t = Accessory r s t => t
instance Row.Cons s t r' r => Accessory (Record r) s t
-- User code:
type Env =
{ readFile :: String -> String
, writeFile :: String -> String -> String
, log :: String -> String
}
mkEnvAff :: Env
mkEnvAff = do
let
readFile :: Access Env "readFile" _
readFile path = path
writeFile :: Access Env "writeFile" _
writeFile path content = path <> content
log :: Access Env "log" _
log msg = msg <> "foo"
{ readFile, writeFile, log }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment