1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{- |
     Author  : Kai-Oliver Prott
     Version : October 2024

     Datatype and operations to handle Positions.
-}





{-# OPTIONS_FRONTEND -Wno-incomplete-patterns #-}

module Curry.Position where

data Position
  = Position Int Int
  | NoPos
  deriving (Eq, Ord, Show, Read)

line :: Position -> Int
line (Position l _) = l

column :: Position -> Int
column (Position _ c) = c

-- | Distance between the row of the first and the second argument
rowDist :: Position -> Position -> Int
rowDist NoPos           NoPos           = 0
rowDist (Position {})   NoPos           = 0
rowDist NoPos           (Position {})   = 0
rowDist (Position r1 _) (Position r2 _) = r2 - r1

incr :: Position -> Int -> Position
incr NoPos              _ = NoPos
incr (Position row col) n = Position row (col + n)