From 890e6df09884277f9fcd5fd6b706091a2e23e6ea Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Mon, 30 Apr 2018 17:07:01 -0400 Subject: [PATCH] Ranges and Spans have lower bounds. --- src/Data/Range.hs | 6 +++++- src/Data/Span.hs | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Data/Range.hs b/src/Data/Range.hs index 280303b77..51f9048f4 100644 --- a/src/Data/Range.hs +++ b/src/Data/Range.hs @@ -7,9 +7,10 @@ module Data.Range , subtractRange ) where -import Prologue import Data.Aeson import Data.JSON.Fields +import Data.Semilattice.Lower +import Prologue -- | A half-open interval of integers, defined by start & end indices. data Range = Range { start :: {-# UNPACK #-} !Int, end :: {-# UNPACK #-} !Int } @@ -51,3 +52,6 @@ instance Ord Range where instance ToJSONFields Range where toJSONFields Range{..} = ["sourceRange" .= [ start, end ]] + +instance Lower Range where + lowerBound = Range 0 0 diff --git a/src/Data/Span.hs b/src/Data/Span.hs index aaef4c9ad..cd1a7a928 100644 --- a/src/Data/Span.hs +++ b/src/Data/Span.hs @@ -9,10 +9,11 @@ module Data.Span , emptySpan ) where -import Prologue import Data.Aeson ((.=), (.:)) import qualified Data.Aeson as A import Data.JSON.Fields +import Data.Semilattice.Lower +import Prologue -- | Source position information data Pos = Pos @@ -56,3 +57,6 @@ instance A.FromJSON Span where instance ToJSONFields Span where toJSONFields sourceSpan = [ "sourceSpan" .= sourceSpan ] + +instance Lower Span where + lowerBound = Span (Pos 1 1) (Pos 1 1)