{-# OPTIONS_GHC -dsuppress-all -dno-suppress-type-signatures -dno-typeable-binds -dsuppress-uniques #-} module Prec where import Data.Foldable import Data.Maybe data Value = A | B | C | D | E deriving Eq prec' :: Value -> [[Value]] -> Int prec' v = fromMaybe 0 . foldl' f Nothing where f (Just !len) _ = Just (len + 1) f Nothing vs | v `elem` vs = Just 1 | otherwise = Nothing {-# INLINE prec' #-} order :: [[Value]] order = [ [ B ], [ A, D ], [ C ] ] {-# INLINE order #-} prec :: Value -> Int prec v = prec' v order