| Copyright | (c) Justin Le 2018 |
|---|---|
| License | BSD3 |
| Maintainer | justin@jle.im |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
AOC.Solver
Contents
Description
Types to drive the challenge runner and help speed up/clean up solutions.
Synopsis
- data a :~> b = MkSol {}
- withSolver :: (String -> Maybe String) -> String :~> String
- withSolver' :: (String -> String) -> String :~> String
- data SomeSolution where
- MkSomeSolWH :: (a :~> b) -> SomeSolution
- MkSomeSolNF :: (NFData a, NFData b) => (a :~> b) -> SomeSolution
- pattern MkSomeSol :: forall a b. (a :~> b) -> SomeSolution
- data SolutionError
- runSolution :: (a :~> b) -> String -> Either SolutionError String
- runSomeSolution :: SomeSolution -> String -> Either SolutionError String
- ssIsNF :: SomeSolution -> Bool
- runSolutionWith :: Map String Dynamic -> (a :~> b) -> String -> Either SolutionError String
- runSomeSolutionWith :: Map String Dynamic -> SomeSolution -> String -> Either SolutionError String
- dyno :: forall a. (Typeable a, ?dyno :: DynoMap) => String -> Maybe a
- dyno_ :: forall a. (Typeable a, ?dyno :: DynoMap) => String -> a -> a
Documentation
Abstracting over the type of a challenge solver to help with cleaner solutions.
A a encapsulates something that solves a challenge with input
type :~> ba into a response of type b.
Consists of a parser, a shower, and a solver. The solver solves
a general a -> function, and the parser and shower are used
to handle the boilerplate of parsing and printing the solution.Maybe b
withSolver' :: (String -> String) -> String :~> String Source #
Construct a :~> from just a normal String -> String solver.
Does no parsing or special printing treatment.
data SomeSolution where Source #
Wrap an a and hide the type variables so we can put
different solutions in a container.:~> b
Constructors
| MkSomeSolWH :: (a :~> b) -> SomeSolution | |
| MkSomeSolNF :: (NFData a, NFData b) => (a :~> b) -> SomeSolution |
Bundled Patterns
| pattern MkSomeSol :: forall a b. (a :~> b) -> SomeSolution | Handy pattern to work with both |
data SolutionError Source #
Errors that might happen when running a :~> on some input.
Instances
| Eq SolutionError Source # | |
Defined in AOC.Solver Methods (==) :: SolutionError -> SolutionError -> Bool # (/=) :: SolutionError -> SolutionError -> Bool # | |
| Ord SolutionError Source # | |
Defined in AOC.Solver Methods compare :: SolutionError -> SolutionError -> Ordering # (<) :: SolutionError -> SolutionError -> Bool # (<=) :: SolutionError -> SolutionError -> Bool # (>) :: SolutionError -> SolutionError -> Bool # (>=) :: SolutionError -> SolutionError -> Bool # max :: SolutionError -> SolutionError -> SolutionError # min :: SolutionError -> SolutionError -> SolutionError # | |
| Show SolutionError Source # | |
Defined in AOC.Solver Methods showsPrec :: Int -> SolutionError -> ShowS # show :: SolutionError -> String # showList :: [SolutionError] -> ShowS # | |
| Generic SolutionError Source # | |
Defined in AOC.Solver Associated Types type Rep SolutionError :: Type -> Type # | |
| NFData SolutionError Source # | |
Defined in AOC.Solver Methods rnf :: SolutionError -> () # | |
| type Rep SolutionError Source # | |
runSolution :: (a :~> b) -> String -> Either SolutionError String Source #
Run a :~> on some input.
runSomeSolution :: SomeSolution -> String -> Either SolutionError String Source #
Run a SomeSolution on some input.
ssIsNF :: SomeSolution -> Bool Source #
Check if a SomeSolution is equipped with an NFData instance on the
types
DynoMap
Arguments
| :: Map String Dynamic | map of dynamic values for testing with |
| -> (a :~> b) | |
| -> String | |
| -> Either SolutionError String |
Run a :~> on some input, with a map of dynamic values for testing
Arguments
| :: Map String Dynamic | map of dynamic values for testing with |
| -> SomeSolution | |
| -> String | |
| -> Either SolutionError String |
Run a SomeSolution on some input, with a map of dynamic values for
testing
dyno :: forall a. (Typeable a, ?dyno :: DynoMap) => String -> Maybe a Source #
From a ?dyno Implicit Params, look up a value at a given key. Meant
to be used with TypeApplications:
'dyno' @"hello"
This can be used within the body of sSolve, since it will always be
called with the implicit parameter.
When called on actual puzzle input, result will always be Nothing.
But, for some test inputs, there might be supplied values.
This is useful for when some problems have parameters that are different with test inputs than for actual inputs.
A version of dyno taking a default value in case the key is not
in the map. When called on actual puzzle input, this is always id.
However, for some test inputs, there might be supplied values.
Meant to be used with TypeApplications:
'dyno_' @"hello" 7
This is useful for when some problems have parameters that are different with test inputs than for actual inputs.