tvl-depot/haskell-file/f.hs
William Carroll 8d00a456a0 Beging work to port f.el to Haskell
This is a work-in-progress. I'd like to add a README to this project to explain
my intention. The goal, roughly, is to port Elisp's fantastic f.el module to
Haskell. I consider Haskell APIs to be useful but somewhat sloppily designed. In
the same spirit as Elixir wrapping Erlang APIs, many of the functions I intend
to define will simply wrap existing Haskell APIs, but with a hopefully cleaner
API that I find more intuitive.
2020-01-15 14:29:18 +00:00

47 lines
1.2 KiB
Haskell

module F
( join
) where
import System.FilePath.Posix (FilePath)
import qualified System.FilePath.Posix as F
-- TODO: Move this to a misc.hs, prelude.hs, operators.hs; somewhere.
(|>) :: a -> (a -> b) -> b
(|>) a f = f a
infixl 1 |>
-- TODO: Move this to a test_utils.hs or elsewhere.
simpleAssert :: (Eq a) => a -> a -> ()
simpleAssert x y =
if x == y then
()
else
error "Assertion error"
--------------------------------------------------------------------------------
-- Library
--------------------------------------------------------------------------------
join :: [FilePath] -> FilePath
join = F.joinPath
--------------------------------------------------------------------------------
-- Tests
--------------------------------------------------------------------------------
expected :: [([FilePath], FilePath)]
expected = [ (["path"], "path")
, (["/path"], "/path")
, (["path", "to", "file"], "path/to/file")
, (["/path", "to", "file"], "/path/to/file")
, (["/"], "/")
]
runTests :: [()]
runTests =
fmap (\(input, expected) -> simpleAssert (join input) expected) expected
main :: IO ()
main = do
print runTests
pure ()