You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been playing around with functions to build Vec n as from infinite Streams and state-like functions (e.g.). We could certainly have a function like fromFunctor :: (Functor f1, Applicative f2) => ... -> f1 a -> f2 (Vec n a). This would be able to subsume* the existing implementations of fromListPrefix and fromList.
* fromListPrefix certainly; fromList may be a proud nail.
Here's what I've got so far:
newtypeFromFunctorf1f2na=FromFunctor{getFromFunctor:: (Functorf1, Functorf2) =>f1a->f2 (Vecna) }fromFunctor::forallf1f2na.
(SNatIn, Functorf1, Applicativef2) =>
(f1a->f2a) ->
(f1a->f1a) ->f1a->f2 (Vecna)
fromFunctor mkHead mkTail = getFromFunctor $ induction1 start step
where start ::FromFunctorf1f2 'Z a
start =FromFunctor$const$pureVNilstep::forallm.FromFunctorf1f2ma->FromFunctorf1f2 ('S m) a
step (FromFunctor f) =FromFunctor$\f_1 ->(:::)<$> (mkHead f_1) <*> (f $ mkTail f_1)
-- These usage examples, while useful, would involve new dependencies: fromStream::SNatIn=>Streama->Vecna
fromStream = runIdentity . (fromFunctor (Identity.Data.Stream.head) Data.Stream.tail)
unfold::forallsna.SNatIn=>
(s-> (a, s)) ->
(s-> (Vecna, s))
unfold = runState . (fromFunctor idid) . state
Would you like me to put together a pull request?
The text was updated successfully, but these errors were encountered:
I've been playing around with functions to build
Vec n a
s from infiniteStreams
and state-like functions (e.g.). We could certainly have a function likefromFunctor :: (Functor f1, Applicative f2) => ... -> f1 a -> f2 (Vec n a)
. This would be able to subsume* the existing implementations offromListPrefix
andfromList
.*
fromListPrefix
certainly;fromList
may be a proud nail.Here's what I've got so far:
Would you like me to put together a pull request?
The text was updated successfully, but these errors were encountered: