Plan 9 from Bell Labs’s /usr/web/sources/contrib/fernan/nhc98/src/hmake/Compat.hs

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


-----------------------------------------------------------------------------
-- |
-- Module      :  Compat
-- Copyright   :  Thomas Hallgren
-- 
-- Maintainer  :  Malcolm Wallace <[email protected]>
-- Stability   :  Stable
-- Portability :  All
--
--  Library with LML compatible functions.
-----------------------------------------------------------------------------

module Compat where
--import Either
--import Maybe
import ListUtil(assocDef, lconcatMap)
import QSort(sortLe)
import Char

#if defined(__HASKELL98__)
#define isAlphanum isAlphaNum
#endif

assocFail :: (Eq a) => a -> [(a, b)] -> b
assocFail x xs = assocDef xs (error "assocFail") x

getenvi s =
	case Nothing {-getEnvi s-} of
	  Nothing -> Left "not found"
	  Just x -> Right x

mix :: [[a]] -> [a] -> [a]
mix [] d = []
mix (x:xs) d = x++case xs of [] -> []; _ -> d ++ mix xs d

splitAtElem :: (Eq a) => a -> [a] -> ([a], [a])
splitAtElem v [] = ([],[])
splitAtElem v (x:xs) | v == x = ([],xs)
		     | otherwise = let (a,b) = splitAtElem v xs
				   in  (x:a, b)

takeWord :: String -> (String, String)
takeWord [] = ([],[])
takeWord (' ':cs) = takeWord cs
takeWord ('\n':cs) = takeWord cs
takeWord ('\t':cs) = takeWord cs
takeWord (c:cs) | isAlpha c = let (w,cs1) = span (\c->isAlphanum c || c=='_') cs in (c:w,cs1)
		| isDigit c = let (w,cs') = span isDigit cs in (c:w, cs')
		| otherwise = ([c], cs)

while :: (a -> Bool) -> (a -> a) -> a -> a
while f g x = if f x then while f g (g x) else x

difference :: (Eq a) => [a] -> [a] -> [a]
difference l1 l2 = filter (`notElem` l2) l1

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].