Alternative formulation of Stream
- Dominant language
- Haskell
- Stars
- 892
- Forks
- 99
- PR merge metrics
- No merged PRs in 30d
Description
Here is what kind of Stream I came to independently, when I was playing with purescript-parsing:
``` purescript
class Stream f c | f -> c where
uncons :: f -> Maybe { head :: c, tail :: f, updatePos :: Position -> Position }
stripPrefix :: Prefix f -> f -> Maybe { rest :: f, updatePos :: Position -> Position }
class HasUpdatePosition a where
updatePos :: Position -> a -> Position
newtype Prefix a = Prefix a
-- example implementation for list
instance (Eq a, HasUpdatePosition a) => Stream (List.List a) a where
uncons f = L.uncons f <#> \({ head, tail}) ->
{ head, tail, updatePos: (_ `updatePos` head)}
stripPrefix (Prefix p) s = List.stripPrefix (List.Pattern p) s <#> \rest ->
{ rest, updatePos: unwrap (fold (p <#> (flip updatePos >>> Endo)))}
```
https://github.com/purescript-contrib/purescript-parsing/pull/62
I think this formulation is nicer as you don't need to carry updatePosition function around, and I don't see why you need the `m` in `uncons` too.
Would like your thoughts on this formulation.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.