Search results

This module provides the Effect type, which is used to represent native effects. The Effect type provides a typed API for effectful computations, while at the same time generating efficient JavaScript.

P purescript-effect

A native effect. The type parameter denotes the return type of running the effect, that is, an Effect Int is a possibly-effectful computation which eventually produces a value of the type Int when it finishes.

P purescript-effect M Effect
P purescript-pipes M Pipes.Core

Type synonym for using Effect as an effect.

P purescript-run M Run
P purescript-causal-graphs M Causal.Kernel
effect :: forall a n. Named n { cause :: a, effect :: a } -> Named (Effect n) a
P purescript-causal-graphs M Causal.Kernel
effect :: forall props a. String -> Effect (a -> a) -> FormBuilder props a a

A dummy form that, whenever the specified key changes, performs an effect. It sets the form data to the result of the effect and returns it.

P purescript-lumi-components M Lumi.Components.Form

An Effect with base type st.

P purescript-refract M Refract
P purescript-pipes M Pipes.Core
P purescript-echarts M ECharts.Types.Phantom
effect0 :: forall b a. String -> a -> b
P purescript-weber M Weber.Event

The base functor of the Effect free monad.

P purescript-refract M Refract
P purescript-pux-echarts M Pux.ECharts
P purescript-key-based-diff M KeyBasedDiff
P purescript-effect M Effect.Uncurried
P purescript-effect M Effect.Uncurried
P purescript-effect M Effect.Uncurried
P purescript-effect M Effect.Uncurried
P purescript-effect M Effect.Uncurried
P purescript-effect M Effect.Uncurried
P purescript-effect M Effect.Uncurried
P purescript-effect M Effect.Uncurried
P purescript-effect M Effect.Uncurried
P purescript-lazy-joe M Lazy.Joe
effectful :: forall f output. Effectful f output => f -> output
P purescript-lazy-joe M Lazy.Joe

This module defines the Ref type for mutable value references, as well as actions for working with them.

You'll notice that all of the functions that operate on a Ref (e.g. new, read, write) return their result wrapped in an Effect. Working with mutable references is considered effectful in PureScript because of the principle of purity: functions should not have side effects, and should return the same result when called with the same arguments. If a Ref could be written to without using Effect, that would cause a side effect (the effect of changing the result of subsequent reads for that Ref). If there were a function for reading the current value of a Ref without the result being wrapped in Effect, the result of calling that function would change each time a new value was written to the Ref. Even creating a new Ref is effectful: if there were a function for creating a new Ref with the type forall s. s -> Ref s, then calling that function twice with the same argument would not give the same result in each case, since you'd end up with two distinct references which could be updated independently of each other.

Note: Control.Monad.ST provides a pure alternative to Ref when mutation is restricted to a local scope.

P purescript-refs
P purescript-effect M Effect.Uncurried
P purescript-aff
P purescript-aff M Effect.Aff.Compat
P purescript-now
P purescript-has-js-rep M HasJSRep
P purescript-aff M Effect.Aff.Compat
EffectFnAff :: forall a. (EffectFn2 (EffectFnCb Error) (EffectFnCb a) EffectFnCanceler) -> EffectFnAff a
P purescript-aff M Effect.Aff.Compat
P purescript-avar
P purescript-tscompat M Data.TSCompat.Class
P purescript-tscompat M Data.TSCompat.Class
effectCrash :: forall a. String -> Effect a
P purescript-specular M Specular.Internal.Incremental
effectfully :: forall st eff a. (st -> Aff eff a) -> Effect eff st a

Perform a Control.Monad.Aff action and return a result.

P purescript-refract M Refract
effectsOver :: forall @f @a. Functor f => FreeS f a -> Array (f Unit)

Collect every possible effect into an Array.

P purescript-selective-functors M Control.Selective.Free
P purescript-effect
P purescript-js-timers
effectToPoll :: Effect ~> Poll

Turn an Effect into a poll

P purescript-hyrule M FRP.Poll
effectsUnder :: forall @f @a. Functor f => FreeS f a -> Array (f Unit)

Collect every required effect into an Array.

P purescript-selective-functors M Control.Selective.Free
P purescript-effect
P purescript-random
effectScatter :: forall m i. Monad m => (CommandsT EffectScatterI m) ~> (CommandsT (effectScatter :: I | i) m)
P purescript-echarts M ECharts.Commands
P purescript-unlift

Module defining the Worker type and a low-level API for interacting with worker threads.

P purescript-workly
P purescript-framer-motion M Framer.Motion.Types
P purescript-console
effectCanceler :: Effect Unit -> Canceler

A canceler from an Effect action.

P purescript-aff M Effect.Aff
P purescript-promises
P purescript-echarts M ECharts.Types.Phantom
P purescript-aff-bus
P purescript-tscompat M Data.TSCompat.Class
P purescript-rito M Rito.Core
EffectComposer :: forall payload. (Ctor payload) -> EffectComposer payload
P purescript-rito M Rito.Core
P purescript-rito M Rito.Renderers.WebGL.EffectComposer
EffectComposer :: EffectComposer' -> EffectComposer
P purescript-rito M Rito.Renderers.WebGL.EffectComposer
effectComposer :: forall payload. { effectComposer :: TEffectComposer } -> WebGLRenderer payload -> Event EffectComposer -> Array (APass payload) -> EffectComposer payload
P purescript-rito M Rito.Renderers.WebGL.EffectComposer
effectComposer :: Effect (Promise TEffectComposer)
P purescript-rito M Rito.THREE
P purescript-avar

Module containing Channels for communicating across Worker thread boundaries

> -- setup required to run examples
> import Effect.Aff.Link
> import Effect (Effect)
> import Effect.Unsafe (unsafePerformEffect)
> import Effect.Aff (Aff)
> import Test.Deasync (unsafeBlockOnAff)
> runAff = unsafeBlockOnAff
> runEff = unsafePerformEffect
P purescript-workly
effect_disjoint :: forall m n. Proof (AreDisjoint n m) -> Proof (AreDisjoint (Effect n) m)
P purescript-causal-graphs M Causal.Kernel
P purescript-rito M Rito.Renderers.WebGL.EffectComposer

This module defines types for effectful uncurried functions, as well as functions for converting back and forth between them.

This makes it possible to give a PureScript type to JavaScript functions such as this one:

function logMessage(level, message) {
  console.log(level + ": " + message);
}

In particular, note that logMessage performs effects immediately after receiving all of its parameters, so giving it the type Data.Function.Fn2 String String Unit, while convenient, would effectively be a lie.

One way to handle this would be to convert the function into the normal PureScript form (namely, a curried function returning an Effect action), and performing the marshalling in JavaScript, in the FFI module, like this:

-- In the PureScript file:
foreign import logMessage :: String -> String -> Effect Unit
// In the FFI file:
exports.logMessage = function(level) {
  return function(message) {
    return function() {
      logMessage(level, message);
    };
  };
};

This method, unfortunately, turns out to be both tiresome and error-prone. This module offers an alternative solution. By providing you with:

  • the ability to give the real logMessage function a PureScript type, and
  • functions for converting between this form and the normal PureScript form,

the FFI boilerplate is no longer needed. The previous example becomes:

-- In the PureScript file:
foreign import logMessageImpl :: EffectFn2 String String Unit
// In the FFI file:
exports.logMessageImpl = logMessage

You can then use runEffectFn2 to provide a nicer version:

logMessage :: String -> String -> Effect Unit
logMessage = runEffectFn2 logMessageImpl

(note that this has the same type as the original logMessage).

Effectively, we have reduced the risk of errors by moving as much code into PureScript as possible, so that we can leverage the type system. Hopefully, this is a little less tiresome too.

Here's a slightly more advanced example. Here, because we are using callbacks, we need to use mkEffectFn{N} as well.

Suppose our logMessage changes so that it sometimes sends details of the message to some external server, and in those cases, we want the resulting HttpResponse (for whatever reason).

function logMessage(level, message, callback) {
  console.log(level + ": " + message);
  if (level > LogLevel.WARN) {
    LogAggregatorService.post("/logs", {
      level: level,
      message: message
    }, callback);
  } else {
    callback(null);
  }
}

The import then looks like this:

foreign import logMessageImpl
 EffectFn3
   String
   String
   (EffectFn1 (Nullable HttpResponse) Unit)
   Unit

And, as before, the FFI file is extremely simple:

exports.logMessageImpl = logMessage

Finally, we use runEffectFn{N} and mkEffectFn{N} for a more comfortable PureScript version:

logMessage ::
  String ->
  String ->
  (Nullable HttpResponse -> Effect Unit) ->
  Effect Unit
logMessage level message callback =
  runEffectFn3 logMessageImpl level message (mkEffectFn1 callback)

The general naming scheme for functions and types in this module is as follows:

  • EffectFn{N} means, an uncurried function which accepts N arguments and performs some effects. The first N arguments are the actual function's argument. The last type argument is the return type.
  • runEffectFn{N} takes an EffectFn of N arguments, and converts it into the normal PureScript form: a curried function which returns an Effect action.
  • mkEffectFn{N} is the inverse of runEffectFn{N}. It can be useful for callbacks.
P purescript-effect

This module defines an effect, actions and handlers for working with JavaScript exceptions.

P purescript-exceptions
P purescript-aff
P purescript-aff M Effect.Aff.Compat
EffectFnCanceler :: (EffectFn3 Error (EffectFnCb Error) (EffectFnCb Unit) Unit) -> EffectFnCanceler
P purescript-aff M Effect.Aff.Compat

Type for any user-created Reducer function that takes an Action for a specific reducer, the entire state, and returns a new copy of the state

P purescript-radox M Radox.Internal.Types
P purescript-aff-cache
P purescript-aff-retry

This module provides compatability functions for constructing Affs which are defined via the FFI.

P purescript-aff
P purescript-unlift
P purescript-stablename
effectComposerAff :: Aff TEffectComposer
P purescript-rito M Rito.THREE
effectComposerPass :: forall payload. { effectComposerPass :: TEffectComposerPass } -> EffectComposer payload -> APass payload
P purescript-rito M Rito.Renderers.WebGL.EffectComposerPass
effectComposerPass :: Effect (Promise TEffectComposerPass)
P purescript-rito M Rito.THREE
P purescript-aff-parallel

Module defining the Worker type and a low-level API for interacting with parent threads from the worker module.

P purescript-workly
P purescript-console
P purescript-aff-reattempt
P purescript-aff-throttler
P purescript-postgresql
P purescript-rito M Rito.Core
P purescript-promises
effectComposerPassAff :: Aff TEffectComposerPass
P purescript-rito M Rito.THREE
P purescript-promises

Bindings for the AbortController and AbortSignal classes. See each type's respective documentation.

P purescript-js-abort-controller
P purescript-workly
P purescript-postgresql
P purescript-exceptions
effectfulAudioInterpret :: STRef Global Int -> AudioInterpret (FFIAudioSnapshot -> Effect Unit)
P purescript-ocarina M Ocarina.Interpret
P purescript-wags M WAGS.Interpret
P purescript-wags M WAGS.Interpret
effectfulThreeInterpret :: STRef Global Int -> ThreeInterpret (Payload)
P purescript-rito M Rito.Interpret
P purescript-postgresql