Skip to content

Instantly share code, notes, and snippets.

@monadplus
Last active October 31, 2019 18:24
Show Gist options
  • Save monadplus/5192ad516e18726f8bc6e86cfe6dc277 to your computer and use it in GitHub Desktop.
Save monadplus/5192ad516e18726f8bc6e86cfe6dc277 to your computer and use it in GitHub Desktop.
Haskell notes
g :: b -> c
f :: r -> a -> b
(g .) . f :: r -> a -> c

[x+1..] -- [x+1, x+2, ..]

The thread that runs main in a Haskell program is a bound thread (slow). The best way around this problem is just to create a new thread from the main and work in that instead. [Parallelism and Concurrency in Haskell, chapter 15, page 248].

-- fromIntegral is broken
>>> fromIntegral (2^1280 ::Integer) :: Word64
0

Yoneda Lemma:

newtype Yoneda f a = Yoneda { runYoneda :: forall b. (a -> b) -> f b }

liftYoneda :: Functor f => f a -> Yoneda f a
liftYoneda a = Yoneda (\f -> fmap f a)

lowerYoneda :: Yoneda f a -> f a
lowerYoneda (Yoneda f) = f id

co-Yoneda Lemma (contravariant functor):

data Coyoneda f a where
  Coyoneda :: (b -> a) -> f b -> Coyoneda f a

liftCoyoneda :: f a -> Coyoneda f a
liftCoyoneda = Coyoneda id

lowerCoyoneda :: Functor f => Coyoneda f a -> f a
lowerCoyoneda (Coyoneda f m) = fmap f m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment