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

NonEmptyList/comonad seems off #52

Open
joneshf opened this issue Jan 31, 2019 · 1 comment
Open

NonEmptyList/comonad seems off #52

joneshf opened this issue Jan 31, 2019 · 1 comment

Comments

@joneshf
Copy link
Contributor

joneshf commented Jan 31, 2019

@MonoidMusician and I were discussing NonEmptyList/comonad in slack, and it seems like it's not working as intended. In particular, the tail is always an empty list. It seems like the coherence with Functor doesn't match. We hope that map f x = extend (\x -> f (extract x)) x, but it doesn't seem to:

let NonEmptyList = ./NonEmptyList/Type

let extend = (./NonEmptyList/comonad).extend

let extract = (./NonEmptyList/comonad).extract

let map = (./NonEmptyList/functor).map

let f : Natural  Natural = λ(x : Natural)  x

let nel : NonEmptyList Natural = { head = 1, tail = [ 2, 3, 4 ] }

in  { left =
        map Natural Natural f nel
    , right =
        extend
        Natural
        Natural
        (λ(x : NonEmptyList Natural)  f (extract Natural x))
        nel
    }
$ dhall <<< ./bunk.dhall
{ left =
    { head = 1, tail = [ 2, 3, 4 ] }
, right =
    { head = 1, tail = [] : List Natural }
}

I was going to send a PR, but extend always throws me for a loop. So if someone wants to PR, go for it.

@FintanH
Copy link
Contributor

FintanH commented Jan 31, 2019

So the error is indeed in extend, where I didn't propagate the function to the tail of the list.

My first thought was to write something like List a -> Optional (NonEmptyList a). Then do maybe [] (toList . extend f) (fromList nel.tail)

But I'm not sure how to a) write fromList and b) get around not being able to do recursion with extend there.

One option may be to define NonEmptyList in terms of recursion schemes (dada cc @sellout).

If we can't fix this in bhat then we need to remove this instance entirely.

EDIT: Fixed pseudocode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants