-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from haskell-works/newhoggy/new-ToString-typeclass
Adopt some useful modules from `hw-polysemy`
- Loading branch information
Showing
5 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module HaskellWorks.FilePath | ||
( exeSuffix, | ||
addExeSuffix, | ||
) where | ||
|
||
import qualified HaskellWorks.OS as OS | ||
|
||
import qualified Data.List as L | ||
import Data.Monoid | ||
import Data.String | ||
|
||
exeSuffix :: String | ||
exeSuffix = if OS.isWin32 then ".exe" else "" | ||
|
||
addExeSuffix :: String -> String | ||
addExeSuffix s = if ".exe" `L.isSuffixOf` s | ||
then s | ||
else s <> exeSuffix |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module HaskellWorks.OS | ||
( isWin32, | ||
) where | ||
|
||
import Data.Bool | ||
import Data.Eq | ||
import System.Info | ||
|
||
-- | Determine if the operating system is Windows. | ||
isWin32 :: Bool | ||
isWin32 = os == "mingw32" | ||
{-# INLINE isWin32 #-} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module HaskellWorks.Stack | ||
( callerModuleName, | ||
) where | ||
|
||
import Data.Function | ||
import Data.Maybe (listToMaybe, maybe) | ||
import Data.String | ||
import Data.Tuple | ||
import GHC.Stack (HasCallStack, callStack, getCallStack, | ||
srcLocModule) | ||
|
||
-- | Get the module name of the caller. | ||
callerModuleName :: HasCallStack => String | ||
callerModuleName = maybe "<no-module>" (srcLocModule . snd) (listToMaybe (getCallStack callStack)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module HaskellWorks.String | ||
( ToString(..), | ||
) where | ||
|
||
import Data.Function | ||
import Data.String | ||
import Data.Text (Text) | ||
import qualified Data.Text as T | ||
import qualified Data.Text.Lazy as LT | ||
|
||
class ToString a where | ||
toString :: a -> String | ||
|
||
instance ToString String where | ||
toString = id | ||
|
||
instance ToString Text where | ||
toString = T.unpack | ||
|
||
instance ToString LT.Text where | ||
toString = LT.unpack |