Plan 9 from Bell Labs’s /usr/web/sources/contrib/fernan/nhc98/src/prelude/Ix/CIx.hs

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


module Ix where

class (Ord a) => Ix a  where
    range     :: (a,a) -> [a]
    index     :: (a,a) -> a -> Int
    inRange   :: (a,a) -> a -> Bool
    rangeSize :: (a,a) -> Int

    rangeSize b@(l,h)
	| null (range b) = 0
	| otherwise      =  index b h + 1

                    -- NB: replacing "null (range b)" by  "not (l <= h)"
                    -- fails if the bounds are tuples.  For example,
                    --      (1,2) <= (2,1)
                    -- but the range is nevertheless empty
                    --      range ((1,2),(2,1)) = []


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].