This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE RankNTypes, MultiParamTypeClasses, FunctionalDependencies #-} | |
module Main7 where | |
sumL :: [Int] -> Int | |
sumL [] = 0 | |
sumL (x:xs) = x + sumL xs | |
sumL1 :: [Int] -> Int | |
sumL1 [] = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- X = presheaf ^ profunctor | |
-- Yoneda = X (->) | |
newtype X p f a = X { runX :: forall b. p a b -> f b } | |
hoistX :: forall p f g. (f ~> g) -> (X p f ~> X p g) | |
hoistX phi (X f) = X (\g -> phi (f g)) | |
withX :: forall w p f a. (Category p, Functor f, Comonad w, Sieve p w) => (X p f a -> X p f a) -> (f a -> f a) | |
withX phi = lowerX @p @f . phi . liftX @w @p @f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module HEADT where | |
import Prelude | |
import Control.Alternative (class Alt, class Alternative, class Plus, empty, (<|>)) | |
import Control.MonadZero (guard) | |
import Data.Either (Either(..)) | |
import Data.Eq (class Eq1, eq1) | |
import Data.Identity (Identity(..)) | |
import Data.Leibniz (type (~), coerceSymm) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Prelude | |
import Control.Lazy (fix) | |
import Control.MonadZero (guard, (<|>)) | |
import Data.Foldable (oneOfMap) | |
import Data.Functor.Mu (Mu, roll, unroll) | |
import Data.Functor.Variant (VariantF) | |
import Data.Functor.Variant as VF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Functor.Day | |
import Data.Functor.Identity | |
import Data.Functor.Compose | |
import Data.Profunctor.Composition | |
import Data.Profunctor.Yoneda | |
import Data.Profunctor | |
import Control.Monad | |
import Control.Applicative | |
import qualified Control.Category as C | |
import qualified Control.Arrow as A |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module LensExample where | |
import Prelude | |
import Data.Array (filter) | |
import Data.Generic.Rep (class Generic) | |
import Data.Generic.Rep.Show (genericShow) | |
import Data.Lens (Traversal, traversed, wander, (.~), (^..), (+~)) | |
import Data.Traversable (traverse) | |
import Effect (Effect) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Append t = Append t t | |
derive instance functorAppend :: Functor Append | |
type Semigroup' r = (append :: V.FProxy Append | r) | |
newtype Semigroup t = Semigroup (V.VariantF (Semigroup' ()) t) | |
derive instance functorSemigroup :: Functor Semigroup | |
_append = SProxy :: SProxy "append" | |
append :: forall a. Algebra Semigroup a => a -> a -> a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
newtype Circle = Circle { circleRadius :: Number, circleCenter :: Tuple Number Number } | |
derive instance genericCircle :: Generic Circle _ | |
instance showCircle :: Show Circle where | |
show c = genericShow c | |
instance eqCircle :: Eq Circle where | |
eq x y = genericEq x y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type MuV t = Mu (VariantF t) | |
inv :: forall a b f s. RowCons s (FProxy f) a b | |
=> IsSymbol s | |
=> Functor f | |
=> SProxy s | |
-> f (Mu (VariantF b)) | |
-> Mu (VariantF b) | |
inv x = In <<< (inj x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | A “flushing” 'stream', with an additional coalgebra for flushing the | |
-- remaining values after the input has been consumed. This also allows us to | |
-- generalize the output away from lists. | |
fstream | |
:: (Cursive t (XNor a), Cursive u f, Corecursive u f, Traversable f) | |
=> Coalgebra f b -> (b -> a -> b) -> Coalgebra f b -> b -> t -> u | |
fstream ψ g ψ' = go | |
where | |
go c x = | |
let fb = ψ c |