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

Try

Description

Try is a synonym for Either ShowS, and is used for results of partial operations which return either Right something when defined or Left report when there is a problem (where report 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 ShowS a Source #

Try is a synonym for Either ShowS. Used for results of partial functions which return either Right something when defined or Left r when there is a problem where r is a (prepending) failure report. Note: ShowS = String -> String makes prepending Strings efficient as composition Note: Either ShowS (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 - prepends s at the front of a failure report if exp fails with Left report but does nothing otherwise.

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

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

failReport :: String -> Try a Source #

failReport s - creates a failure (Left), prepending s for the failure report

failReports :: [String] -> Try a Source #

failReports ss - creates a failure (Left), concatenating ss for the failure report

runTry :: Try a -> a Source #

Extract the (Right) result from a Try, raising an error if the Try is Left r. The failure report (from Left r) is converted to a Stirng and passed to error.

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

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

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 [] (so is NOT a fail)

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

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

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

tryAtLeastOne rs - returns Right with the list of successful results if there are any, but Left with a fail report otherwise. The error report will include the concatenated reports from multiple failures.

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 multiple failures.

Orphan instances

Show ShowS Source #

Cheating - a ShowS function is "shown" by applying it to a String

Instance details

Methods

showsPrec :: Int -> ShowS -> ShowS #

show :: ShowS -> String #

showList :: [ShowS] -> ShowS #