quebex

A software analysis framework built around the QBE intermediate language

git clone https://git.8pit.net/quebex.git

 1-- SPDX-FileCopyrightText: 2025 Sören Tempel <soeren+git@soeren-tempel.net>
 2--
 3-- SPDX-License-Identifier: GPL-3.0-only
 4
 5module Language.QBE.Backend
 6  ( SolverError (..),
 7    prefixLength,
 8  )
 9where
10
11import Control.Exception (Exception)
12
13data SolverError
14  = UnknownResult
15  deriving (Show)
16
17instance Exception SolverError
18
19------------------------------------------------------------------------
20
21-- | Determine the length of the common prefix of two lists.
22prefixLength :: (Eq a) => [a] -> [a] -> Int
23prefixLength = prefixLength' 0
24  where
25    prefixLength' :: (Eq a) => Int -> [a] -> [a] -> Int
26    prefixLength' n [] _ = n
27    prefixLength' n _ [] = n
28    prefixLength' n (x : xs) (y : ys)
29      | x == y = prefixLength' (n + 1) xs ys
30      | otherwise = n