This file contains hidden or 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
import Control.Monad.IO.Class | |
import Control.Monad.Codensity | |
import System.IO | |
managedActions :: Codensity IO () | |
managedActions = do | |
input <- Codensity $ withFile "in.txt" ReadMode | |
output <- Codensity $ withFile "out.txt" WriteMode | |
contents <- liftIO $ hGetContents input |
This file contains hidden or 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 Application where | |
import Data.Profunctor | |
newtype Application request response = Application {unApplication :: request -> IO response} | |
instance Profunctor Application where | |
dimap actOnRequest actOnResponse application = Application $ (fmap actOnResponse) . (unApplication application) . actOnRequest |
This file contains hidden or 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
-- Combining Maps using the Applicative idiom. | |
{-# LANGUAGE DeriveFunctor, DeriveFoldable, DeriveTraversable #-} | |
module ApplicativeMap where | |
import Data.Map.Strict (Map) | |
import qualified Data.Map as Map | |
-- When combining multiple Applicative computations, a common Haskell idiom is | |
-- to use (<$>) and (<*>) to combine the results using a function: |
This file contains hidden or 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
import System.IO.Unsafe | |
main :: IO () | |
main = do | |
thing 1 | |
thing 2 | |
thing 3 | |
thing' 1 | |
thing' 2 |
This file contains hidden or 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
{- stack --resolver lts-16.8 --install-ghc exec ghci --package "protolude text binary" -} | |
{-# LANGUAGE DeriveGeneric, DuplicateRecordFields, ExistentialQuantification, FlexibleContexts, RankNTypes, ScopedTypeVariables, StandaloneDeriving #-} | |
{- ghcid -c "stack X.hs" -} | |
module Existenial where | |
import Data.Text | |
import Data.Binary | |
import GHC.Generics |
This file contains hidden or 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
{- cabal: | |
build-depends: base | |
build-depends: transformers | |
ghc-options: -threaded | |
-} | |
import Control.Concurrent (myThreadId, threadDelay, forkOS) | |
import Control.Monad (forever, void) | |
import Control.Monad.IO.Class (liftIO) |
This file contains hidden or 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
-- Based on https://gist.github.com/jship/d2237fad40cfb34166d82597735fbacf | |
-- | |
-- The above example demonstrates how to flatten all the routes in a record of | |
-- records of routes, in order to bind a long list of top-level 'Link' | |
-- functions. | |
-- | |
-- Below, I demonstrate how to instead go from a record of records of routes to | |
-- a record of records of 'Link's, and how to easily navigate the resulting | |
-- nested record. | |
{-# LANGUAGE DataKinds, DeriveGeneric, DerivingStrategies, FlexibleContexts, GADTs, TypeApplications, TypeOperators #-} |
OlderNewer