about summary refs log tree commit diff
path: root/haskell-file/f.hs
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-01-15T14·29+0000
committerWilliam Carroll <wpcarro@gmail.com>2020-01-15T14·29+0000
commit8d00a456a03aed5dc4a8944519e4d3d44c446ad8 (patch)
tree58ea1c24116fa19d5fda3d14d5914ca6d864dd4e /haskell-file/f.hs
parentd4d8397e5ffe6734ed5861e48ce475848956a3fe (diff)
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.
Diffstat (limited to 'haskell-file/f.hs')
-rw-r--r--haskell-file/f.hs47
1 files changed, 47 insertions, 0 deletions
diff --git a/haskell-file/f.hs b/haskell-file/f.hs
new file mode 100644
index 0000000000..9ddb930ee1
--- /dev/null
+++ b/haskell-file/f.hs
@@ -0,0 +1,47 @@
+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 ()