Created
December 13, 2020 12:40
-
-
Save sigevsky/6041c1b85b502a9ac94b837436b31457 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE GeneralisedNewtypeDeriving #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
module Amb where | |
import Control.Monad.Reader | |
import Control.Monad.Cont | |
import Data.Maybe (isJust) | |
import Data.List (find) | |
require :: Eq a => a -> a -> (Maybe b -> ContT t m ()) -> ContT t m () | |
require a b esc = if a == b then pure () else esc Nothing | |
blah = untilJustIterate [1, 2, 3] $ \n -> | |
untilJustIterate ['a', 'b', 'c'] $ \l -> | |
callCC $ \k -> Just <$> do | |
require n 2 k | |
require l 'a' k | |
return $ show (n * 2) <> " " <> show l | |
untilJustIterate :: Monad m => [a] -> (a -> m (Maybe b)) -> m (Maybe b) | |
untilJustIterate [] f = pure Nothing | |
untilJustIterate (x: xs) f = f x >>= \case | |
Nothing -> untilJustIterate xs f | |
a -> pure a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment