Skip to content

Instantly share code, notes, and snippets.

@peacememories
Last active May 30, 2017 15:56
Show Gist options
  • Save peacememories/fe597e6f4f908e6097eb8a9f26df791f to your computer and use it in GitHub Desktop.
Save peacememories/fe597e6f4f908e6097eb8a9f26df791f to your computer and use it in GitHub Desktop.
AppendFile.hs
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeSynonymInstances #-}
module Path.Class
(AppendFile)
where
import Path (Dir, File, Path, Rel)
import qualified Path as Path
import System.FilePath (FilePath)
import qualified System.FilePath as FilePath
class AppendFile d where
type FileName d :: *
type Result d :: *
(</#>) :: d -> FileName d -> Result d
instance AppendFile FilePath where
type FileName FilePath = FilePath
type Result FilePath = FilePath
(</#>) = (FilePath.</>)
instance AppendFile (Path b Dir) where
type FileName (Path b Dir) = Path Rel File
type Result (Path b Dir) = Path b File
(</#>) = (Path.</>)
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeSynonymInstances #-}
module Path.ClassWithMaybe
(AppendFile)
where
import Control.Monad
import Path (Dir, File, Path, Rel)
import qualified Path as Path
import System.FilePath (FilePath)
import qualified System.FilePath as FilePath
class AppendFile d where
type FileName d :: *
type Result d :: *
(</#>) :: d -> FileName d -> Result d
instance AppendFile FilePath where
type FileName FilePath = FilePath
type Result FilePath = Maybe FilePath
dir </#> file = do
guard $ FilePath.isRelative file
return $ dir FilePath.</> file
instance AppendFile (Path b Dir) where
type FileName (Path b Dir) = Path Rel File
type Result (Path b Dir) = Path b File
(</#>) = (Path.</>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment