summaryrefslogtreecommitdiff
path: root/Utility.hs
blob: a160cb7db347bed555f524c741887dc37551d50f (plain)
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
module Utility where

import Data.List

--if any of the predicates returns true, options returns true
options :: [a -> Bool] -> a -> Bool
options l x = any id [f x | f <- l]

fixpoint :: (Eq a) => (a -> a) -> a -> a
fixpoint f x = let fx = f x in if fx == x then x else fixpoint f fx

setcompareBy :: (a -> a -> Bool) -> [a] -> [a] -> Bool
setcompareBy _ [] [] = True
setcompareBy _ [] _ = False
setcompareBy _ _ [] = False
setcompareBy p a@(x:xs) b = length a == length b && setcompareBy p xs (deleteBy p x b)

deleteIndex :: Int -> [a] -> [a]
deleteIndex 0 (_:xs) = xs
deleteIndex i (x:xs) | i > 0 = x : deleteIndex (i-1) xs

fromLeft :: Either a b -> a
fromLeft (Left a) = a
fromLeft (Right _) = undefined

fromRight :: Either a b -> b
fromRight (Left _) = undefined
fromRight (Right b) = b