Last active
May 30, 2017 15:56
-
-
Save peacememories/fe597e6f4f908e6097eb8a9f26df791f to your computer and use it in GitHub Desktop.
AppendFile.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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.</>) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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