All of the profunctor optics kind have the same, very simple, pattern:
type AnOptic p s t a b = p a b -> p s t
type Optic c s t a b = forall p. c p => AnOptic p s t a b
type Iso s t a b = Optic Profunctor s t a b
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE AllowAmbiguousTypes #-} | |
{-# LANGUAGE TypeApplications #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE RankNTypes #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE InstanceSigs #-} |
{-# OPTIONS_GHC -Wall #-} | |
{-# LANGUAGE RankNTypes #-} | |
{-# LANGUAGE ConstraintKinds #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
import Control.Monad | |
import Data.Bifunctor | |
type AnOptic p s t a b = p a b -> p s t |
Benchmark bench-trans-speed: RUNNING... | |
benchmarking 1/20 modify/pure/2000 | |
time 1.033 μs (1.022 μs .. 1.052 μs) | |
0.991 R² (0.981 R² .. 0.997 R²) | |
mean 1.130 μs (1.084 μs .. 1.207 μs) | |
std dev 182.7 ns (129.1 ns .. 265.3 ns) | |
variance introduced by outliers: 95% (severely inflated) | |
benchmarking 1/20 modify/ParserT State/2000 | |
time 1.250 μs (1.236 μs .. 1.264 μs) |
{-# LANGUAGE RankNTypes #-} | |
module LensM where | |
import Control.Applicative (Const(..)) | |
import Data.Functor.Identity (Identity(..)) | |
import Data.Functor.Contravariant (Contravariant) | |
import Data.Functor.Compose | |
class Functor f => MfaAms f where |
import Control.Monad ((>=>)) | |
import Data.Map (Map) | |
import qualified Data.Map as M | |
import GHC.Generics (Generic) | |
import Optics | |
data MLens m s a = MLens | |
{ mview :: s -> m a | |
, mset :: a -> s -> m s | |
} |
module Main where | |
import Data.Maybe (fromJust) | |
data Expr | |
= Var String | |
| Lam String Expr | |
| App Expr Expr | |
| Lit Int | |
| Prim PrimOp Expr Expr | |
| Let (String, Expr) Expr |
module Main where | |
import Data.Either.Extra (maybeToEither) | |
data Expr | |
= Var String | |
| Lam String Expr | |
| App Expr Expr | |
| Lit Int | |
| Prim PrimOp Expr Expr |
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE LambdaCase #-} | |
{-# LANGUAGE TupleSections #-} | |
module Calc ( | |
Calc, call, runCalc, runCalcM, extractCalls, | |
runCalcSortBy, runCalcSortOn, runCalcSort, | |
contramapRes, mapInit, traverseInit | |
) where |