Module

Control.Ask

Package
purescript-ask
Repository
Mateiadrielrafael/purescript-ask

Typeclass based implicit parameters

#Asks Source

class Asks 

Constraint created in order to make Ask un-implementable

#Ask Source

class (Asks) <= Ask a  where

Ask is the type class representation of an implicit parameter.

Example:

foo :: Ask Int => Int -> String
foo bar = show (bar + ask)

The value can then later be supplied using provide:

(provide 4 foo) 2 -- "6"
provide 4 (foo 3) -- "7"

Members

  • ask :: a

    Retrives an implicit parameter from the context

#askFor Source

askFor :: forall a p. Ask a => p a -> a

Equivalent to ask except for accepting a Proxy for specifying the exact requested type

#provide Source

provide :: forall result a. a -> (Ask a => result) -> result

Provide an implicit parameter to a computation which requires it

#local Source

local :: forall a b r. (a -> b) -> (Ask b => r) -> (Ask a => r)

Run a function over an implicit parameter

Note: Be careful while using this to map over the value without updating the type.

-- evaluates to `1`, not `2`
provide 1 (local ((*) 2) (ask @Int))
Modules
Control.Ask