Skip to content

Instantly share code, notes, and snippets.

@abbradar
Created June 13, 2016 18:56
Show Gist options
  • Save abbradar/6d85ea7db99313e91ee837f02735009f to your computer and use it in GitHub Desktop.
Save abbradar/6d85ea7db99313e91ee837f02735009f to your computer and use it in GitHub Desktop.
{-# LANGUAGE PatternSynonyms, ViewPatterns #-}
import Data.List
import Data.Foldable
import Control.Monad.State
import Data.Distributive
fromList :: (Applicative m, Distributive m, Traversable m) => [a] -> Maybe (m a)
fromList xs = do
(ys, []) <- runStateT (traverse (\_ -> StateT uncons) (pure ())) xs
return ys
pattern FixedList :: (Distributive m, Traversable m, Applicative m) => m a -> [a]
pattern FixedList m <- (fromList -> Just m) where
FixedList m = toList m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment