Skip to content

Instantly share code, notes, and snippets.

int main(int argc, char** argv) {
using namespace folly::gen;
auto v = from (m) | mapped(f) | as<vector>();
return v.size();
}
module Search where
import Control.Applicative
import Control.Monad
import Data.Foldable
import Data.Monoid
import Data.Sequence
import Data.Traversable
import Prelude hiding (foldl)
import Test.QuickCheck
("/usr/local/Cellar/emacs/24.3/Emacs.app/Contents/MacOS/Emacs" "search.hs")
Loading /Users/tulloch/.emacs.d/tulloch.el (source)...done
For information about GNU Emacs and the GNU system, type C-h C-a.
Loading vc-git...done
Contacting host: api.github.com:443
Opening TLS connection to `api.github.com'...
Opening TLS connection with `gnutls-cli --insecure -p 443 api.github.com'...failed
Opening TLS connection with `gnutls-cli --insecure -p 443 api.github.com --protocols ssl3'...failed
Opening TLS connection with `openssl s_client -connect api.github.com:443 -no_ssl2 -ign_eof'...done
Opening TLS connection to `api.github.com'...done
module Search where
import Control.Applicative
import Control.Monad
import Data.Foldable
import Data.Monoid
import Data.Sequence
import Data.Traversable
import Prelude hiding (foldl)
import Test.QuickCheck
Welcome to the Emacs shell
~/Code/haskell/search $ runhaskell search.hs
Passed:
1
Leaf 0
Passed:
1
Branch (Leaf (-1)) (Leaf 1)
Passed:
module Search where
import Control.Applicative
import Control.Monad
import Data.Foldable
import Data.Monoid
import Data.Sequence
import Data.Traversable
import Prelude hiding (foldl)
import Test.QuickCheck
search :: Eq a => Expand a -> a -> Seq (Node a) -> Bool
search expand target queue =
let recur = search expand target
in case viewl queue of
EmptyL -> False
Leaf value :< xs -> (value == target) || recur xs
Branch left right :< xs ->
recur (expand xs left right)
search :: Eq a => Expand a -> a -> Seq (Node a) -> Bool
search expand target queue =
let recur = search expand target
in case viewl queue of
EmptyL -> False
Leaf value :< xs -> (value == target) && recur xs
Branch left right :< xs ->
recur (expand xs left right)
Welcome to the Emacs shell
~/Code/haskell/search $ runhaskell search.hs
Failed:
0
Leaf 0
*** Failed! Falsifiable (after 1 test):
0
Leaf 0
~/Code/haskell/search $
~/Code/haskell/search $ runhaskell search.hs
Failed:
0
Leaf 0
*** Failed! Falsifiable (after 1 test):
0
Leaf 0