Closed gspia closed 4 years ago
Great idea! I would be happy to add Unfoldr and Iterate. Would you like to make a PR?
The definition of Unfoldr could be simplified a little, with only two families, one to apply the coalgebra, and one to pattern-match on it.
> -- type instance Eval (Unfoldr (f :: b -> Exp (Maybe (a, b))) c ) =
> -- Note, if we wrote the above type instance, then the last parameter cannot
> -- have 'b' as a name. Why?
> type instance Eval (Unfoldr f c) =
The name b is already taken for the kind of the argument of f, which is also the kind of c.
Thanks for the suggestion & ok, I can try to prepare a PR.
About the names: I just realized that it wasn't Iterate
but rather Replicate
.
I'll try to simplify the Unfoldr
and it leaves less badly named helper families then in there. In my first trial I tried to write directly a recursive version but then the evaluation of Unfoldr
just diverged to somewhere... Still don't exactly, why it didn't work and why there is this need of "indirection" (=use of helper families). I think it is conceptually something that could be elaborated more for people to be aware of that kind of "corner" cases. But how?
Anyhow, how about the examples? Maybe just put them into the haddocks so that people can quickly start playing with them? (I'll prepare the PR this way and of course I'm ready to modify or remove them if not ok.)
For lists, it is easy to also define Concat
and ConcatMap
. Those actually proved already to be quite useful. I'll add them at the same time.
Ok, the PR is now merged so it is probably ok to close this one.
Thanks! (Closed by #16)
In a PR you can use keywords to link it to an issue so it gets closed automatically. So for example you make a PR and in the message on github you can write "Closes #15
" in plain text.
https://github.blog/2013-05-14-closing-issues-via-pull-requests/
Hi
Would
Unfoldr
possibly fit in into this lib?It could be defined like
After that, it is possible to define hylomorphism for type level lists:
and Iterate and Factorial etc.
The following gist contains headers and the above definitions in one place:
unfoldr gist