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 MultiWayIf #-} | |
import Control.Applicative (empty) | |
import Control.Monad | |
import Control.Monad.ST | |
import Control.Monad.Trans (lift) | |
import Control.Monad.Trans.Maybe | |
import Control.Monad.Trans.State.Strict | |
import Data.Bits | |
import qualified Data.ByteString.Char8 as BS8 | |
import Data.Foldable (for_) |
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 RecordWildCards #-} | |
module Main where | |
import qualified Data.ByteString.Char8 as BS | |
main :: IO () | |
main = BS.interact $ out . solve "RB" . BS.init where | |
out (s, e) | |
= BS.pack (show s) <> BS.pack " " <> BS.pack (show e) |
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 BangPatterns #-} | |
module Lib | |
( foldr | |
) where | |
import Control.Concurrent | |
import Control.Concurrent.MVar | |
import Data.Foldable (foldl') | |
import Prelude hiding (foldr) | |
import System.IO.Unsafe |
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 BangPatterns #-} | |
import Control.Monad | |
import Data.List | |
import qualified Data.Map.Strict as M | |
main :: IO () | |
main = do | |
cases <- readLn | |
replicateM_ cases $ do | |
getLine |
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
shortestLongest :: [[[a]]] -> [[a]] | |
shortestLongest = step1 [] [] . (map . map) dup where | |
step1 :: [[[a]]] -> [[([a], [a])]] -> [[([a], [a])]] -> [[a]] | |
step1 [] xsss [] = step1 [] [] (reverse xsss) | |
step1 res _ [] = concat $ reverse res | |
step1 res acc (xss : xsss) = | |
case step2 xss of | |
(maxs, []) -> step1 (maxs : res) [] xsss | |
(_, nonNull) | |
| null res -> step1 [] (nonNull : acc) xsss |
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
{-# OPTIONS_GHC -Wincomplete-patterns #-} | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE DeriveFoldable #-} | |
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE RankNTypes #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE StandaloneDeriving #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE TypeApplications #-} |
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
module Lib | |
( prerun | |
) where | |
import Control.Concurrent | |
import Data.IORef | |
import qualified Data.Map as M | |
import Data.Maybe | |
prerun :: (IO a -> IO (IO b)) -> IO (IO a -> IO b) |
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 GADTs #-} | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# OPTIONS_GHC -fwarn-incomplete-patterns #-} | |
module Lib where | |
import Data.Kind |
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 TupleSections #-} | |
module MaterializeForceBy | |
( Tree (..) | |
, materializeForcedBy | |
) where | |
import System.IO.Unsafe | |
import Data.IORef | |
import Data.Maybe |
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 RankNTypes #-} | |
module ForceElems | |
( forceElems | |
) where | |
-- See https://github.com/effectfully/haskell-challenges/tree/master/force-elems | |
forceElems :: Traversable t => t a -> t a | |
forceElems = unE . traverse (E ($!)) | |
data E a = E (forall y. (a -> y) -> a -> y) a |