module Hascal (operators,eval,hascal) where

import           Control.Arrow     (second)
import           Data.Function     (on)
import           Data.Number.CReal


hascal :: String -> CReal
hascal = eval operators


operators :: [(Char, CReal -> CReal -> CReal)]
operators = [ ('+', (+))
            , ('-', (-))
            , ('/', (/))
            , ('*', (*))
            , ('^', (**))
            ]-- Respecting operator precedence,
             -- you can add custom infix operators.


eval :: [(Char, CReal -> CReal -> CReal)] -> String -> CReal
eval []          a = read a
eval l@((c,f):s) a | z /= ""   = on f (eval l.($m)) fst snd
                   | otherwise = eval s a
                   where m@(_,z) = second (drop 1) $ break (==c) a