Suppose you have a few modules in an application which needs to request and parse data from a JSON api:
- Http
- Json parsing
- Business logic, something to do with Images
Each of these can fail in their own way:
| {-# LANGUAGE OverloadedStrings #-} | |
| module Network.Wai.Middleware.FileUpload where | |
| import Control.Monad.Trans.Resource | |
| import qualified Data.ByteString as S | |
| import qualified Data.Foldable as F | |
| import Data.Monoid | |
| import Data.String (fromString) | |
| import Network.HTTP.Types.URI (Query, QueryItem) | |
| import Network.Wai |
| > import Test.QuickCheck | |
| > import Data.List | |
| > quickCheck (\xs -> (snd . Data.List.splitAt 3) xs === drop 3 xs) | |
| +++ OK, passed 100 tests. | |
| > |
| module Foo where | |
| import Data.Functor.Identity | |
| -- | OK | |
| -- | |
| -- We are going to build 2 functions | |
| -- * something that collects all the items in a list of futures | |
| -- * something that recursively gets all the search results from an |
| {-# LANGUAGE TemplateHaskell #-} | |
| {-# LANGUAGE OverloadedStrings #-} | |
| module Data.Omnitrans.OtMatrix.Header where | |
| import Data.Text as T | |
| import Control.Monad | |
| import Data.Serialize as B | |
| import Control.Lens | |
| import Data.Char (chr) | |
| import Data.Word |
This would need de-MTL'ing.
We have a process that builds up lots and lots of matrices row by row.
The calling code calls appendAll a bunch of times for different sub-groups of matrices, and then checkFileWritingConsistency after doing all the sub-groups.
| -- | |
| import Data.Map.Lazy | |
| import Control.Lens | |
| -- We wanted to traverse a structure, but not recompute the function for duplicate keys. And then we also needed cache. | |
| -- It's probably tricky to unlens this. | |
| traverseMemoOf :: (Ord a, Monad f) => Traversal s t a b -> (a -> f b) -> s -> f (t, ML.Map a b) | |
| traverseMemoOf l f z = |
| module EnvParse where | |
| import Control.Lens (from, view, (^.), over, _Left) | |
| import System.IO (stderr, hPutStrLn, hPrint) | |
| import Control.Monad ((<=<)) | |
| import Control.Monad.Reader (ReaderT (..), runReaderT) | |
| import Data.Validation (AccValidation, _AccValidation, _Either) | |
| import System.Environment (getEnvironment) | |
| import System.Exit (exitFailure) | |
| import Text.Read (readEither) |
| {-# LANGUAGE NoMonomorphismRestriction #-} | |
| {-# LANGUAGE OverloadedStrings #-} | |
| module Data.Yaml.Extended (module Data.Yaml.Extended, lift) where | |
| import Data.Aeson.Types | |
| import qualified Data.Text as T | |
| import Control.Monad.State.Strict (StateT, runStateT, unless, lift, get, modify) | |
| import qualified Data.HashMap.Strict as HM (null, delete, keys) | |
| import Data.List (intercalate) |
| {-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
| {-# LANGUAGE DeriveTraversable #-} | |
| {-# LANGUAGE FlexibleInstances #-} | |
| {-# LANGUAGE MultiParamTypeClasses #-} | |
| {-# LANGUAGE UndecidableInstances #-} | |
| {-# OPTIONS_GHC -fno-warn-orphans #-} | |
| module NonEmpty where | |
| import Control.Lens | |
| import Control.Lens.Extras |