PenroseKiteDart-1.0.0: Library to explore Penrose's Kite and Dart Tilings.
Copyright(c) Chris Reade 2021
LicenseBSD-style
Maintainerchrisreade@mac.com
Stabilityexperimental
Safe HaskellSafe-Inferred
LanguageHaskell2010

Tgraph.Try

Description

Try is a synonym for Either String, which is used for results of partial operations which return either Right something when defined or Left string when there is a problem (where string is a failure report). This is to allow computation to continue in failure cases without necessarily raising an error. This module contains functions associated with Try results.

Synopsis

Try - result types with failure reporting (for partial operations).

type Try a = Either String a Source #

Try is a synonym for Either String. Used for results of partial functions which return either Right something when defined or Left string when there is a problem where string is a failure report. Note: Either String (and hence Try) is a monad, and this is used frequently for combining partial operations.

onFail :: String -> Try a -> Try a Source #

onFail s exp - inserts s at the front of failure report if exp fails with Left report

nothingFail :: Maybe b -> String -> Try b Source #

Converts a Maybe Result into a Try result by treating Nothing as a failure (the string s is the failure report on failure). Usually used as infix (exp nothingFail s)

runTry :: Try a -> a Source #

Extract the (Right) result from a Try, producing an error if the Try is Left s. The failure report is passed to error for an error report.

ifFail :: a -> Try a -> a Source #

ifFail a tr - extracts the (Right) result from tr but returning a if tr is Left s.

isFail :: Try a -> Bool Source #

a try result is a failure if it is a Left

concatFails :: [Try a] -> Try [a] Source #

Combines a list of Trys into a single Try with failure overriding success. It concatenates all failure reports if there are any and returns a single Left r. Otherwise it produces Right rs where rs is the list of all (successful) results. In particular, concatFails [] = Right []

ignoreFails :: [Try a] -> [a] Source #

Combines a list of Trys into a list of the successes, ignoring any failures. In particular, ignoreFails [] = []

atLeastOne :: [Try a] -> [a] Source #

atLeastOne rs - returns the list of successful results if there are any, but fails with an error otherwise. The error report will include the concatenated reports from the failures.

noFails :: [Try a] -> [a] Source #

noFails rs - returns the list of successes when all cases succeed, but fails with an error and a concatenated failure report of all failures if there is at least one failure. In particular, noFails [] = []