All Projects → re-xyr → cleff

re-xyr / cleff

Licence: BSD-3-Clause License
Fast and concise extensible effects

Programming Languages

haskell
3896 projects

Projects that are alternatives of or similar to cleff

AudioEffectDynamics
Dynamics Processor (Gate, Compressor & Limiter) for the Teensy Audio Library
Stars: ✭ 23 (-65.15%)
Mutual labels:  effects
Vuc
🎨 基于 Vuejs2 的 Canvas 组件库【服务器挂了。不在提供demo,github自带的静态网站不能发布,因为demo代码找不到了😂。】
Stars: ✭ 52 (-21.21%)
Mutual labels:  effects
ECardFlow
🍭A custom ViewPager for multiple card flow system. && A layout which provide beautiful background effects for ViewPager.
Stars: ✭ 47 (-28.79%)
Mutual labels:  effects
bow-openapi
🌐 Functional HTTP client generator from an OpenAPI/Swagger specification.
Stars: ✭ 47 (-28.79%)
Mutual labels:  effects
shuffle-text
"shuffle-text" is JavaScript text effect library such as cool legacy of Flash.
Stars: ✭ 93 (+40.91%)
Mutual labels:  effects
vue-fake3d-image-effect
✨ A fake 3D Image Effect with WebGL - w/ VueJS - SSR Compatible
Stars: ✭ 15 (-77.27%)
Mutual labels:  effects
L5P-Keyboard-RGB
Cross platform software to control the lighting of the 4 zone keyboard included in the 2020 and 2021 lineup of the Lenovo Legion laptops. Works on Windows and Linux.
Stars: ✭ 79 (+19.7%)
Mutual labels:  effects
pedalboard
Online guitar pedalboard
Stars: ✭ 48 (-27.27%)
Mutual labels:  effects
vuepress-plugin-cursor-effects
🎉 Add a cute click effect to your mouse in your vuepress!
Stars: ✭ 18 (-72.73%)
Mutual labels:  effects
skyline
Some canvas experiments... like drawing a procedurally generated skyline. Also featuring fun explosions :D
Stars: ✭ 24 (-63.64%)
Mutual labels:  effects
FoundryVTT-Sequencer
This module implements a basic pipeline that can be used for managing the flow of a set of functions, effects, sounds, and macros.
Stars: ✭ 25 (-62.12%)
Mutual labels:  effects
limitless-engine
OpenGL C++ Graphics Engine
Stars: ✭ 95 (+43.94%)
Mutual labels:  effects
RainbowTaskbar
Customizable Windows taskbar effects.
Stars: ✭ 39 (-40.91%)
Mutual labels:  effects
pi-stomp
pi-stomp is a DIY high definition, multi-effects stompbox platform for guitar, bass and keyboards
Stars: ✭ 42 (-36.36%)
Mutual labels:  effects
Amazing-Js-Projects
Amazing-Js-Projects
Stars: ✭ 99 (+50%)
Mutual labels:  effects
GlowButton
Beautify your layouts with glowing buttons. Support with a ⭐️ Contributions are welcome! 🙌
Stars: ✭ 54 (-18.18%)
Mutual labels:  effects
zio-http4s-example
For anyone who's struggling to put an http4s server together with ZIO
Stars: ✭ 19 (-71.21%)
Mutual labels:  effects
SongProcessor
A beefed up version of AudioKit's Song Processor with the intention of releasing it on the App Store.
Stars: ✭ 36 (-45.45%)
Mutual labels:  effects
react-awesome-reveal
React components to add reveal animations using the Intersection Observer API and CSS Animations.
Stars: ✭ 564 (+754.55%)
Mutual labels:  effects
QQVoiceChange
Android NDK项目,继承 fmod音频引擎 实现仿QQ变声效果,可实现对录音进行变声,如 萝莉、大叔、搞怪、惊悚、空灵等效果,带领大家熟悉使用Android Studio+ CMake 集成 fmod 等C/C++框架的流程。
Stars: ✭ 26 (-60.61%)
Mutual labels:  effects

cleff - fast and concise extensible effects

GitHub Workflow Status Hackage

cleff is an extensible effects library for Haskell, with a focus on the balance of performance, expressiveness and ease of use. It provides a set of predefined effects that you can conveniently reuse in your program, as well as low-boilerplate mechanisms for defining and interpreting new domain-specific effects on your own.

In essence, cleff offers:

  • Performance:

    cleff does not use techniques like Freer monads or monad transformers. Instead, cleff's Eff monad is essentially implemented as a ReaderT IO. This concrete formulation allows more GHC optimizations to fire, and has lower performance overhead. In microbenchmarks, cleff outperforms polysemy and even mtl.

    The only caveat is that cleff does not support nondeterminism and continuations in the Eff monad - but after all, most effects libraries has broken nondeterminism support, and we encourage users to wrap another monad transformer with support of nondeterminism (e.g. ListT) over the main Eff monad in such cases.

  • Low boilerplate:

    cleff supports user-defined effects and provides simple yet flexible API for implementing them. Implementations of effects are simply case-splitting functions, and users familiar with polysemy or freer-simple will find it very easy to get along with cleff. Take a look at the examples.

  • Interoperability:

    cleff's simple underlying structure allows us to implement near-seamless interop with the current ecosystem, mainly classes like MonadUnliftIO, MonadCatch and MonadBaseControl. In other words, you can directly use libraries like unliftio, exceptions and lifted-async in cleff without writing any "adapter" code.

  • Predictable semantics:

    Traditional effect libraries have many surprising behaviors. For example, mtl reverts the state when an error is thrown, and has a lot more subtleties when interacting with IO. cleff implements State and Writer as IORef operations, and Error as Exceptions, so it is able to interact well with IO and provide semantics that are predictable in the presence of concurrency and exceptions. Moreover, any potentially surprising behavior is carefully documented for each effect.

  • Higher-order effects:

    Higher-order effects are effects that "wraps" monadic computations, like local, catchError and mask. Implementing higher-order effects is often tedious, or outright not supported in most effect libraries. polysemy is the first library that aims to provide easy higher-order effects mechanism with its Tactics API. Following its path, cleff provides a set of combinators that can be used to implement higher-order effects. These combinators are as expressive as polysemy's, and are also easier to use correctly.

  • Ergonomics without sacrificing flexibility:

    Unlike mtl, cleff doesn't have functional dependencies on effects, so you can have e.g. multiple State effects. As a side effect, GHC will sometimes ask you to provide which effect you're operating on via TypeApplications, or otherwise the effect usage will be ambiguous. This can be verbose at times, and we have a solution for that: cleff-plugin is a GHC plugin that works like mtl's functional dependencies, and can resolve most type ambiguities involving effects for you.

Example

This is the code that defines the classic Teletype effect. It only takes 20 lines to define the effect and two interpretations, one using stdio and another reading from and writing to a list:

import Cleff
import Cleff.Input
import Cleff.Output
import Cleff.State
import Data.Maybe (fromMaybe)

-- Effect definition
data Teletype :: Effect where
  ReadTTY :: Teletype m String
  WriteTTY :: String -> Teletype m ()
makeEffect ''Teletype

-- Effect Interpretation via IO
runTeletypeIO :: IOE :> es => Eff (Teletype : es) a -> Eff es a
runTeletypeIO = interpretIO \case
  ReadTTY    -> getLine
  WriteTTY s -> putStrLn s

-- Effect interpretation via other pure effects
runTeletypePure :: [String] -> Eff (Teletype : es) w -> Eff es [String]
runTeletypePure tty = fmap (reverse . snd)
  . runState [] . outputToListState
  . runState tty . inputToListState
  . reinterpret2 \case
    ReadTTY -> fromMaybe "" <$> input
    WriteTTY msg -> output msg

-- Using the effect

echo :: Teletype :> es => Eff es ()
echo = do
  x <- readTTY
  if null x then pure ()
    else writeTTY x >> echo

echoPure :: [String] -> [String]
echoPure input = runPure $ runTeletypePure input echo

main :: IO ()
main = runIOE $ runTeletypeIO echo

See example/ for more examples.

Benchmarks

These are the results of the effect-zoo microbenchmarks, compiled by GHC 8.10.7. Keep in mind that these are very short and synthetic programs, and may or may not tell the accurate performance characteristics of different effect libraries in real use:

  • big-stack: big-stack benchmark result
  • countdown: countdown benchmark result
  • file-sizes: file-sizes benchmark result
  • reinterpretation: reinterpretation benchmark result

Differences from effectful

If you know about effectful, you may notice that cleff and effectful seem to make many similar claims and have a similar underlying implementation. In microbenchmarks, cleff is slightly behind effectful. This may make you confused about the differences between the two libraries. To put it simply, cleff has a more versatile and expressive effect interpretation mechanism, and a lighter weight API. In contrast, effectful gains its performance advantage by providing static dispatch for some internal effects, which means they cannot have multiple interpretations.

References

These are the useful resources that inspired this library's design and implementation.

Papers:

Libraries:

  • eff by Alexis King and contributors.
  • effectful by Andrzej Rybczak and contributors.
  • freer-simple by Alexis King and contributors.
  • polysemy by Sandy Maguire and contributors.

Talks:

Blog posts:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].