nearest :: Int -> [(Expr, Value)] -> (Expr, Value)
-- nearest n ts = minimumBy (compare `on` snd) [(e, abs $ v - n) | (e,v) <- ts]
nearest n ((e,v):evs) = if d == 0 then (e,v)
                                  else search n d (e,v) evs
                          where d = abs (n - v)
nearest :: Int -> [(Expr, Value)] -> (Expr, Value)
nearest n ((e,v):evs) = if d == 0 then (e,v)
                                  else search n d (e,v) evs
                          where d = abs (n - v)
nearest n ((e,v):evs) = if d == 0 then (e,v)
                                  else search n d (e,v) evs
                          where d = abs (n - v)