Compare commits

...

10 Commits

Author SHA1 Message Date
Sanchayan Maity cce60e0790 freemonad: Update the Free monad notebook
Signed-off-by: Sanchayan Maity <maitysanchayan@gmail.com>
2020-08-08 19:01:31 +05:30
Sanchayan Maity 91050d615a Add a notebook on free monad
Signed-off-by: Sanchayan Maity <maitysanchayan@gmail.com>
2020-08-01 19:18:09 +05:30
Sanchayan Maity c56f7f977c README: Add link to the virtual lens meetup
Signed-off-by: Sanchayan Maity <maitysanchayan@gmail.com>
2020-06-06 18:36:48 +05:30
Sanchayan Maity ce6e56a49e Add a nice explanation on existential-types
Signed-off-by: Sanchayan Maity <maitysanchayan@gmail.com>
2020-06-06 18:31:17 +05:30
Sanchayan Maity b1ef1705d3 Add notebook for continuations
Signed-off-by: Sanchayan Maity <maitysanchayan@gmail.com>
2020-04-21 20:33:03 +05:30
Sanchayan Maity 0c904479a5 Add links to existential types articles
Signed-off-by: Sanchayan Maity <maitysanchayan@gmail.com>
2020-04-20 20:12:08 +05:30
Sanchayan Maity b4bf90923d Add some more links to README
Signed-off-by: Sanchayan Maity <maitysanchayan@gmail.com>
2020-03-21 17:56:18 +05:30
Sanchayan Maity 0fb8217770 Add contravariant notebook
Signed-off-by: Sanchayan Maity <maitysanchayan@gmail.com>
2020-03-21 17:53:55 +05:30
Sanchayan Maity cadd5d2406 Update README
Signed-off-by: Sanchayan Maity <maitysanchayan@gmail.com>
2020-03-20 20:58:26 +05:30
Sanchayan Maity 3b32e4c073 Add links to various posts on CPS
Signed-off-by: Sanchayan Maity <maitysanchayan@gmail.com>
2020-03-11 21:22:48 +05:30
6 changed files with 1764 additions and 0 deletions

View File

@ -16,6 +16,10 @@ result/bin/ihaskell-notebook
One can link the binary in local/bin to the above so that it can be run from
anywhere.
# My Lens talk
https://www.youtube.com/watch?v=uZLN2x3u2kg
# References
namc.in/2018-03-26-lenses-part-1
@ -26,6 +30,12 @@ https://www.schoolofhaskell.com/user/griba/easier_lenses_profunctor_based_with_m
https://www.schoolofhaskell.com/user/liyang/profunctors
https://bartoszmilewski.com/2015/07/13/from-lenses-to-yoneda-embedding/
https://github.com/hablapps/DontFearTheProfunctorOptics
https://twanvl.nl/blog/haskell/isomorphism-lenses
https://blog.jez.io/lens-intuition/
https://blog.jle.im/entry/lenses-products-prisms-sums.html

174
continuations.ipynb Normal file
View File

@ -0,0 +1,174 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<style>/* Styles used for the Hoogle display in the pager */\n",
".hoogle-doc {\n",
"display: block;\n",
"padding-bottom: 1.3em;\n",
"padding-left: 0.4em;\n",
"}\n",
".hoogle-code {\n",
"display: block;\n",
"font-family: monospace;\n",
"white-space: pre;\n",
"}\n",
".hoogle-text {\n",
"display: block;\n",
"}\n",
".hoogle-name {\n",
"color: green;\n",
"font-weight: bold;\n",
"}\n",
".hoogle-head {\n",
"font-weight: bold;\n",
"}\n",
".hoogle-sub {\n",
"display: block;\n",
"margin-left: 0.4em;\n",
"}\n",
".hoogle-package {\n",
"font-weight: bold;\n",
"font-style: italic;\n",
"}\n",
".hoogle-module {\n",
"font-weight: bold;\n",
"}\n",
".hoogle-class {\n",
"font-weight: bold;\n",
"}\n",
".get-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"display: block;\n",
"white-space: pre-wrap;\n",
"}\n",
".show-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"margin-left: 1em;\n",
"}\n",
".mono {\n",
"font-family: monospace;\n",
"display: block;\n",
"}\n",
".err-msg {\n",
"color: red;\n",
"font-style: italic;\n",
"font-family: monospace;\n",
"white-space: pre;\n",
"display: block;\n",
"}\n",
"#unshowable {\n",
"color: red;\n",
"font-weight: bold;\n",
"}\n",
".err-msg.in.collapse {\n",
"padding-top: 0.7em;\n",
"}\n",
".highlight-code {\n",
"white-space: pre;\n",
"font-family: monospace;\n",
"}\n",
".suggestion-warning { \n",
"font-weight: bold;\n",
"color: rgb(200, 130, 0);\n",
"}\n",
".suggestion-error { \n",
"font-weight: bold;\n",
"color: red;\n",
"}\n",
".suggestion-name {\n",
"font-weight: bold;\n",
"}\n",
"</style><span class='get-type'>(>>-) :: forall r a. MCont r a -> (a -> r) -> r</span>"
],
"text/plain": [
"(>>-) :: forall r a. MCont r a -> (a -> r) -> r"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"newtype MCont r a = MCont { (>>-) :: (a -> r) -> r }\n",
"\n",
":t (>>-)\n",
"\n",
"instance Functor (MCont r) where\n",
" fmap f cra = MCont $ \\k -> cra >>- \\a -> k (f a)\n",
" \n",
"instance Applicative (MCont r) where\n",
" pure a = MCont $ \\aTor -> aTor a\n",
" cf <*> cx = MCont $ \\bTor ->\n",
" cx >>- \\a ->\n",
" cf >>- \\f ->\n",
" bTor (f a)\n",
" \n",
"instance Monad (MCont r) where\n",
" return = pure\n",
" cra >>= f = MCont $ \\bTor ->\n",
" cra >>- \\a ->\n",
" (f a) >>- \\b ->\n",
" bTor b\n",
" \n",
"join' :: MCont r (MCont r a) -> MCont r a\n",
"join' ccx = MCont $ \\k ->\n",
" ccx >>- \\cx -> -- extract inner continuation\n",
" cx >>- \\x -> -- extract value of inner continuation\n",
" k x -- wrap value in k again"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"square :: Int -> MCont r Int\n",
"square x = MCont $ \\k -> k (x ^ 2)\n",
"\n",
"add :: Int -> Int -> MCont r Int\n",
"add x y = MCont $ \\k -> k (x + y)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"pythagoras :: Int -> Int -> MCont r Int\n",
"pythagoras x y = do\n",
" xsquare <- square x\n",
" ysquare <- square y\n",
" add xsquare ysquare"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Haskell",
"language": "haskell",
"name": "haskell"
},
"language_info": {
"codemirror_mode": "ihaskell",
"file_extension": ".hs",
"name": "haskell",
"pygments_lexer": "Haskell",
"version": "8.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

37
continuations.md Normal file
View File

@ -0,0 +1,37 @@
http://okmij.org/ftp/continuations/#tutorial
http://okmij.org/ftp/Haskell/types.html
https://gist.github.com/lexi-lambda/d97b8187a9b63619af29689e9fa1b880
http://hackage.haskell.org/package/liboleg-2010.1.10.0/docs/Control-CCRef.html
https://hackage.haskell.org/package/CC-delcont-0.2.1.0/candidate/docs/Control-Monad-CC.html
http://www.haskellforall.com/2012/06/you-could-have-invented-free-monads.html
http://www.haskellforall.com/2012/12/the-continuation-monad.html
https://blog.poisson.chat/posts/2019-10-26-reasonable-continuations.html
http://okmij.org/ftp/continuations/implementations.html
https://free.cofree.io/2020/01/02/cps/
https://maxhallinan.com/posts/2019/10/22/how-does-the-continuation-monad-work/
https://github.com/iokasimov/pipeline
https://hexagoxel.de/postsforpublish/posts/2018-09-09-cont-part-one.html
https://github.com/rain-1/continuations-study-group/wiki/Reading-List
http://blog.ielliott.io/continuations-from-the-ground-up/
https://deque.blog/2017/12/08/continuation-passing-style-free-monads-and-direct-style-free-monads/
https://vaibhavsagar.com/blog/2017/05/22/discovering-continuations/
http://blog.sigfpe.com/2008/12/mother-of-all-monads.html
https://github.com/quchen/articles/blob/master/cont_monad.md

58
contravariant.ipynb Normal file
View File

@ -0,0 +1,58 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Contravariant Functors"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
"{-# LANGUAGE KindSignatures #-}\n",
"\n",
"-- (.) :: (b -> c) -> (a -> b) -> a -> c\n",
"-- contraComp :: (a -> b) -> (b -> c) -> a -> c\n",
"\n",
"-- (.) f g x = f (g x)\n",
"-- contraComp f g x = g (f x)\n",
"\n",
"-- instance Functor (a ->) where\n",
"-- fmap = (.)\n",
"\n",
"-- instance Contravariant (-> z) where\n",
"-- contramap = flip (.)\n",
"\n",
"newtype Predicate a = Predicate { getPredicate :: a -> Bool }\n",
"\n",
"newtype Op b a = Op { getOp :: a -> b }\n",
" \n",
"class Contravariant (f :: * -> *) where\n",
" contramap :: (a -> b) -> f b -> f a\n",
" \n",
"instance Contravariant (Op a) where\n",
" contramap f g = Op $ let bToa = getOp g in bToa . f"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Haskell",
"language": "haskell",
"name": "haskell"
},
"language_info": {
"codemirror_mode": "ihaskell",
"file_extension": ".hs",
"name": "haskell",
"pygments_lexer": "Haskell",
"version": "8.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

22
existential-types.md Normal file
View File

@ -0,0 +1,22 @@
https://gist.github.com/CMCDragonkai/b203769c588caddf8cb051529339635c
http://iveselov.info/posts/2012-08-30-existential-types.html
Great explanation by Anupam Jain in FPNCR Telegram channel :)
Everything gets a forall.
Basically if you see a free variable x in a type signature, assume theres a
*forall x* in front of the signature.
Free variable is just a fancy way to say an undeclared variable. Where *forall*
is the way we declare variables. So if the signature is *foo :: a -> Int*,
the *a* is free because it was not introduced first with a *forall*.
*forall* at type level is like a lambda (\) at the value level. It basically
says somehow I will be given a type and then rest of the implementation can
depend on that type. And in fact some languages like Dhall make it explicit
where they accept an actual type parameter instead of making it implicit
In Dhall it would be something like foo : a:Type -> val:a -> Int
It says foo takes a type, a value of that type, and gives you an Int back.

1463
freemonad.ipynb Normal file

File diff suppressed because it is too large Load Diff