1module Main where 2 3import Prelude 4import Effect 5import Effect.Console (log) 6 7data List a = Cons a (List a) | Nil 8 9data Sequence t = Sequence (forall m a. Monad m => t (m a) -> m (t a)) 10 11sequence :: forall t. Sequence t -> (forall m a. Monad m => t (m a) -> m (t a)) 12sequence (Sequence s) = s 13 14sequenceListSeq :: forall m a. Monad m => List (m a) -> m (List a) 15sequenceListSeq Nil = pure Nil 16sequenceListSeq (Cons x xs) = Cons <$> x <*> sequenceListSeq xs 17 18sequenceList :: Sequence List 19sequenceList = Sequence (sequenceListSeq) 20 21sequenceList' :: Sequence List 22sequenceList' = Sequence ((\val -> case val of 23 Nil -> pure Nil 24 Cons x xs -> Cons <$> x <*> sequence sequenceList' xs)) 25 26sequenceList'' :: Sequence List 27sequenceList'' = Sequence (sequenceListSeq :: forall m a. Monad m => List (m a) -> m (List a)) 28 29sequenceList''' :: Sequence List 30sequenceList''' = Sequence ((\val -> case val of 31 Nil -> pure Nil 32 Cons x xs -> Cons <$> x <*> sequence sequenceList''' xs) :: forall m a. Monad m => List (m a) -> m (List a)) 33 34main = do 35 void $ sequence sequenceList $ Cons (log "Done") Nil 36 void $ sequence sequenceList' $ Cons (log "Done") Nil 37 void $ sequence sequenceList'' $ Cons (log "Done") Nil 38 void $ sequence sequenceList''' $ Cons (log "Done") Nil 39