{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DataKinds      #-}
{-# LANGUAGE GADTs          #-}
{-# LANGUAGE PolyKinds      #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -fplugin=Polysemy.Plugin #-}
module Polysemy.Path where

import Control.Monad
import Path
import Polysemy
import Polysemy.ConstraintAbsorber.MonadCatch
import Polysemy.Error


parseRelFile' :: Members '[Error SomeException] r
              => FilePath
              -> Sem r (Path Rel File)
parseRelFile' :: FilePath -> Sem r (Path Rel File)
parseRelFile' FilePath
x = (MonadThrow (Sem r) =>
 Sem r (Either SomeException (Path Rel File)))
-> Sem r (Either SomeException (Path Rel File))
forall (r :: [(* -> *) -> * -> *]) a.
Member (Error SomeException) r =>
(MonadThrow (Sem r) => Sem r a) -> Sem r a
absorbMonadThrow (Sem r (Path Rel File)
-> Sem r (Either SomeException (Path Rel File))
forall e (r :: [(* -> *) -> * -> *]) a.
Member (Error e) r =>
Sem r a -> Sem r (Either e a)
try (Sem r (Path Rel File)
 -> Sem r (Either SomeException (Path Rel File)))
-> (FilePath -> Sem r (Path Rel File))
-> FilePath
-> Sem r (Either SomeException (Path Rel File))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Sem r (Path Rel File)
forall (m :: * -> *). MonadThrow m => FilePath -> m (Path Rel File)
parseRelFile (FilePath -> Sem r (Either SomeException (Path Rel File)))
-> FilePath -> Sem r (Either SomeException (Path Rel File))
forall a b. (a -> b) -> a -> b
$ FilePath
x) Sem r (Either SomeException (Path Rel File))
-> (Either SomeException (Path Rel File) -> Sem r (Path Rel File))
-> Sem r (Path Rel File)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (SomeException -> Sem r (Path Rel File))
-> (Path Rel File -> Sem r (Path Rel File))
-> Either SomeException (Path Rel File)
-> Sem r (Path Rel File)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either SomeException -> Sem r (Path Rel File)
forall e (r :: [(* -> *) -> * -> *]) a.
MemberWithError (Error e) r =>
e -> Sem r a
throw Path Rel File -> Sem r (Path Rel File)
forall (m :: * -> *) a. Monad m => a -> m a
return

parseAbsFile' :: Members '[Error SomeException] r
              => FilePath
              -> Sem r (Path Abs File)
parseAbsFile' :: FilePath -> Sem r (Path Abs File)
parseAbsFile' FilePath
x = (MonadThrow (Sem r) =>
 Sem r (Either SomeException (Path Abs File)))
-> Sem r (Either SomeException (Path Abs File))
forall (r :: [(* -> *) -> * -> *]) a.
Member (Error SomeException) r =>
(MonadThrow (Sem r) => Sem r a) -> Sem r a
absorbMonadThrow (Sem r (Path Abs File)
-> Sem r (Either SomeException (Path Abs File))
forall e (r :: [(* -> *) -> * -> *]) a.
Member (Error e) r =>
Sem r a -> Sem r (Either e a)
try (Sem r (Path Abs File)
 -> Sem r (Either SomeException (Path Abs File)))
-> (FilePath -> Sem r (Path Abs File))
-> FilePath
-> Sem r (Either SomeException (Path Abs File))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Sem r (Path Abs File)
forall (m :: * -> *). MonadThrow m => FilePath -> m (Path Abs File)
parseAbsFile (FilePath -> Sem r (Either SomeException (Path Abs File)))
-> FilePath -> Sem r (Either SomeException (Path Abs File))
forall a b. (a -> b) -> a -> b
$ FilePath
x) Sem r (Either SomeException (Path Abs File))
-> (Either SomeException (Path Abs File) -> Sem r (Path Abs File))
-> Sem r (Path Abs File)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (SomeException -> Sem r (Path Abs File))
-> (Path Abs File -> Sem r (Path Abs File))
-> Either SomeException (Path Abs File)
-> Sem r (Path Abs File)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either SomeException -> Sem r (Path Abs File)
forall e (r :: [(* -> *) -> * -> *]) a.
MemberWithError (Error e) r =>
e -> Sem r a
throw Path Abs File -> Sem r (Path Abs File)
forall (m :: * -> *) a. Monad m => a -> m a
return

parseRelDir' :: Members '[Error SomeException] r
             => FilePath
             -> Sem r (Path Rel Dir)
parseRelDir' :: FilePath -> Sem r (Path Rel Dir)
parseRelDir' FilePath
x = (MonadThrow (Sem r) => Sem r (Either SomeException (Path Rel Dir)))
-> Sem r (Either SomeException (Path Rel Dir))
forall (r :: [(* -> *) -> * -> *]) a.
Member (Error SomeException) r =>
(MonadThrow (Sem r) => Sem r a) -> Sem r a
absorbMonadThrow (Sem r (Path Rel Dir) -> Sem r (Either SomeException (Path Rel Dir))
forall e (r :: [(* -> *) -> * -> *]) a.
Member (Error e) r =>
Sem r a -> Sem r (Either e a)
try (Sem r (Path Rel Dir)
 -> Sem r (Either SomeException (Path Rel Dir)))
-> (FilePath -> Sem r (Path Rel Dir))
-> FilePath
-> Sem r (Either SomeException (Path Rel Dir))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Sem r (Path Rel Dir)
forall (m :: * -> *). MonadThrow m => FilePath -> m (Path Rel Dir)
parseRelDir (FilePath -> Sem r (Either SomeException (Path Rel Dir)))
-> FilePath -> Sem r (Either SomeException (Path Rel Dir))
forall a b. (a -> b) -> a -> b
$ FilePath
x) Sem r (Either SomeException (Path Rel Dir))
-> (Either SomeException (Path Rel Dir) -> Sem r (Path Rel Dir))
-> Sem r (Path Rel Dir)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (SomeException -> Sem r (Path Rel Dir))
-> (Path Rel Dir -> Sem r (Path Rel Dir))
-> Either SomeException (Path Rel Dir)
-> Sem r (Path Rel Dir)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either SomeException -> Sem r (Path Rel Dir)
forall e (r :: [(* -> *) -> * -> *]) a.
MemberWithError (Error e) r =>
e -> Sem r a
throw Path Rel Dir -> Sem r (Path Rel Dir)
forall (m :: * -> *) a. Monad m => a -> m a
return

parseAbsDir' :: Members '[Error SomeException] r
             => FilePath
             -> Sem r (Path Abs Dir)
parseAbsDir' :: FilePath -> Sem r (Path Abs Dir)
parseAbsDir' FilePath
x = (MonadThrow (Sem r) => Sem r (Either SomeException (Path Abs Dir)))
-> Sem r (Either SomeException (Path Abs Dir))
forall (r :: [(* -> *) -> * -> *]) a.
Member (Error SomeException) r =>
(MonadThrow (Sem r) => Sem r a) -> Sem r a
absorbMonadThrow (Sem r (Path Abs Dir) -> Sem r (Either SomeException (Path Abs Dir))
forall e (r :: [(* -> *) -> * -> *]) a.
Member (Error e) r =>
Sem r a -> Sem r (Either e a)
try (Sem r (Path Abs Dir)
 -> Sem r (Either SomeException (Path Abs Dir)))
-> (FilePath -> Sem r (Path Abs Dir))
-> FilePath
-> Sem r (Either SomeException (Path Abs Dir))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Sem r (Path Abs Dir)
forall (m :: * -> *). MonadThrow m => FilePath -> m (Path Abs Dir)
parseAbsDir (FilePath -> Sem r (Either SomeException (Path Abs Dir)))
-> FilePath -> Sem r (Either SomeException (Path Abs Dir))
forall a b. (a -> b) -> a -> b
$ FilePath
x) Sem r (Either SomeException (Path Abs Dir))
-> (Either SomeException (Path Abs Dir) -> Sem r (Path Abs Dir))
-> Sem r (Path Abs Dir)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (SomeException -> Sem r (Path Abs Dir))
-> (Path Abs Dir -> Sem r (Path Abs Dir))
-> Either SomeException (Path Abs Dir)
-> Sem r (Path Abs Dir)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either SomeException -> Sem r (Path Abs Dir)
forall e (r :: [(* -> *) -> * -> *]) a.
MemberWithError (Error e) r =>
e -> Sem r a
throw Path Abs Dir -> Sem r (Path Abs Dir)
forall (m :: * -> *) a. Monad m => a -> m a
return

stripProperPrefix' :: Members '[Error SomeException] r
                   => Path b Dir
                   -> Path b t
                   -> Sem r (Path Rel t)
stripProperPrefix' :: Path b Dir -> Path b t -> Sem r (Path Rel t)
stripProperPrefix' Path b Dir
x Path b t
y = (MonadThrow (Sem r) => Sem r (Either SomeException (Path Rel t)))
-> Sem r (Either SomeException (Path Rel t))
forall (r :: [(* -> *) -> * -> *]) a.
Member (Error SomeException) r =>
(MonadThrow (Sem r) => Sem r a) -> Sem r a
absorbMonadThrow (Sem r (Path Rel t) -> Sem r (Either SomeException (Path Rel t))
forall e (r :: [(* -> *) -> * -> *]) a.
Member (Error e) r =>
Sem r a -> Sem r (Either e a)
try (Sem r (Path Rel t) -> Sem r (Either SomeException (Path Rel t)))
-> Sem r (Path Rel t) -> Sem r (Either SomeException (Path Rel t))
forall a b. (a -> b) -> a -> b
$ Path b Dir -> Path b t -> Sem r (Path Rel t)
forall (m :: * -> *) b t.
MonadThrow m =>
Path b Dir -> Path b t -> m (Path Rel t)
stripProperPrefix Path b Dir
x Path b t
y) Sem r (Either SomeException (Path Rel t))
-> (Either SomeException (Path Rel t) -> Sem r (Path Rel t))
-> Sem r (Path Rel t)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (SomeException -> Sem r (Path Rel t))
-> (Path Rel t -> Sem r (Path Rel t))
-> Either SomeException (Path Rel t)
-> Sem r (Path Rel t)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either SomeException -> Sem r (Path Rel t)
forall e (r :: [(* -> *) -> * -> *]) a.
MemberWithError (Error e) r =>
e -> Sem r a
throw Path Rel t -> Sem r (Path Rel t)
forall (m :: * -> *) a. Monad m => a -> m a
return