Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add note on Extend and Comonad type classes #516

Open
JordanMartinez opened this issue Sep 8, 2020 · 0 comments
Open

Add note on Extend and Comonad type classes #516

JordanMartinez opened this issue Sep 8, 2020 · 0 comments
Labels
enhancement New feature or request Hello-World Something related to the Hello World folder in this repo

Comments

@JordanMartinez
Copy link
Owner

Bind enables one to compose functions of the type signature a -> m b. This is done via bind/>>=. The composition is >=>:

f :: Int -> Maybe String

g :: String -> Maybe String

h :: String -> Maybe Foo

-- composition enabled despite the function "output" 
-- being wrapped in a `Maybe`
f >=> g >=> h

Extend enables a similar composition. Rather than composing functions of the type a -> m b, it composes functions of the type m a -> b. This is done via extend/<<=. The composition is =>=:

f :: Maybe Int -> String

g :: Maybe String -> String

h :: Maybe String -> Foo

-- composition enabled despite the function "input" 
-- being wrapped in a `Maybe`.
f =>= h =>= g

-- Note: I'm not sure whether the above order is correct
-- it might be `g =>= h =>= f`

Whereas Applicative's pure puts a value into a "box", so that one can use bind to continue to compose functions, Comonad's extract takes a value out of a "box, so that one can use extend to continue to compose functions.

@JordanMartinez JordanMartinez added enhancement New feature or request Hello-World Something related to the Hello World folder in this repo labels Sep 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Hello-World Something related to the Hello World folder in this repo
Projects
None yet
Development

No branches or pull requests

1 participant