jord-0.1.0.0: Geographic position calculations on Great Circles

Copyright(c) 2018 Cedric Liegeois
LicenseBSD3
MaintainerCedric Liegeois <ofmooseandmen@yahoo.fr>
Stabilityexperimental
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010

Data.Geo.Jord.Eval

Contents

Description

Types and functions for evaluating expressions in textual form.

Synopsis

Documentation

data Value Source #

A value accepted and returned by eval.

Constructors

Ang Angle

Angle

AngDec Double

Angle in decimal degrees

Bool Bool

boolean

Double Double

double

Len Length

Length

Gc GreatCircle

GreatCircle

Geo GeoPos

GeoPos

Geos [GeoPos]

list of GeoPos

GeoDec (Double, Double)

latitude and longitude in decimal degrees

GeosDec [(Double, Double)]

list of latitude and longitude in decimal degrees

Vec NVector

NVector

Vecs [NVector]

list of NVectors

Instances
Eq Value Source # 
Instance details

Defined in Data.Geo.Jord.Eval

Methods

(==) :: Value -> Value -> Bool #

(/=) :: Value -> Value -> Bool #

Show Value Source # 
Instance details

Defined in Data.Geo.Jord.Eval

Methods

showsPrec :: Int -> Value -> ShowS #

show :: Value -> String #

showList :: [Value] -> ShowS #

data Vault Source #

 A location for Values to be shared by successive evalations.

type Result = Either String Value Source #

Either an error or a Value.

eval :: String -> Vault -> Result Source #

Evaluates s, an expression of the form "(f x y ..)".

>>> eval "finalBearing (destination (antipode 54°N,154°E) 54° 1000m) 54°N,154°E"
126°

f must be one of the supported functions and each parameter x, y, .. , is either another function call or a String parameter. Parameters are either resolved by name using the Resolve function r or if it returns Nothing, read to an Angle, a Length or a GeoPos.

If the evaluation is successful, returns the resulting Value (Right) otherwise a description of the error (Left).

    vault = emptyVault
    angle = eval "finalBearing 54N154E 54S154W" vault -- Right Ang
    length = eval "distance (antipode 54N154E) 54S154W" vault -- Right Len
    -- parameter resolution from vault
    a1 = eval "finalBearing 54N154E 54S154W" vault
    vault = insert "a1" vault
    a2 = eval "(finalBearing a1 54S154W)" vault

By default, all returned positions are Geo (GeoPos), to get back a Vec (NVector), the expression must be wrapped by toNVector.

    dest = eval "destination 54°N,154°E 54° 1000m" -- Right Geo
    dest = eval "toNVector (destination 54°N,154°E 54° 1000m)" -- Right Vec

Every function call must be wrapped between parentheses, however they can be ommitted for the top level call.

    angle = eval "finalBearing 54N154E 54S154W" -- Right Ang
    angle = eval "(finalBearing 54N154E 54S154W)" -- Right Ang
    length = eval "distance (antipode 54N154E) 54S154W" -- Right Len
    length = eval "distance antipode 54N154E 54S154W" -- Left String

insert :: String -> Value -> Vault -> Vault Source #

insert k v vault inserts value v for key k. Overwrites any previous value.

delete :: String -> Vault -> Vault Source #

delete k vault deletes key k from the vault.

lookup :: String -> Vault -> Maybe Value Source #

lookup k vault looks up the value of key k in the vault.

Orphan instances

MonadFail (Either String) Source # 
Instance details

Methods

fail :: String -> Either String a #