Skip to content

Add note on Extend and Comonad type classes #516

@JordanMartinez

Description

@JordanMartinez

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Hello-WorldSomething related to the Hello World folder in this repoenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions