Created
March 6, 2014 14:45
-
-
Save derekmahar/9391282 to your computer and use it in GitHub Desktop.
Custom function definitions for Haskell AWK (Hawk). Store in .hawk/prelude.gs. See https://github.com/gelisam/hawk for details.
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
{- .hawk/prelude.hs -} | |
{-# LANGUAGE ExtendedDefaultRules, OverloadedStrings #-} | |
import Prelude | |
import qualified Data.ByteString.Char8 as B | |
import qualified Data.ByteString.Lazy as BL | |
import qualified Data.ByteString.Lazy.Search as S | |
import qualified Data.List as L | |
replace :: String -> String -> BL.ByteString -> BL.ByteString | |
replace search replacement input = S.replace (B.pack search) (B.pack replacement) input | |
-- See https://github.com/gelisam/hawk/blob/master/doc/conversions/prelude.hs | |
to :: (Read a) => B.ByteString -> a | |
to = read . B.unpack | |
toBool :: B.ByteString -> Bool | |
toBool = to | |
toDouble :: B.ByteString -> Double | |
toDouble = to | |
toFloat :: B.ByteString -> Float | |
toFloat = to | |
toInt :: B.ByteString -> Int | |
toInt = to | |
toString :: B.ByteString -> String | |
toString = show |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment