3 ms·
| sed '/k/sk' Has-skill $
by fuzztester 2y ago
| sed '/k/sk'
Has-skill
$
- orf 2y agoWrite the full transform in Haskell?
- itishappy 2y ago{-# LANGUAGE OverloadedStrings #-} import Prelude hiding (putStrLn) import Data.Text (Text, replace) import Data.Text.IO (putStrLn) transform :: Text -> Text transform = replace "k" "sk" . replace "ke" "-ki" main :: IO () main = putStrLn $ transform "Haskell"
- fuzztester 2y agoLooks good to me, even as a Haskell ignoramus. I had tried it long back, but found it tough at the time. What is the reason for hiding the putStrLn of Prelude and importing that of Data.Text.IO?
- itishappy 2y agoPrelude takes a `String`, Data.Text.IO works with `Text`. Strings are linked lists of of chars, Text is a more traditional data structure. I tend to write small scripts and use Strings more, but Text is much more efficient for big blocks of text (unsurprisingly). The main reason I used it here was because I couldn't find a `replace` function for `String`, lol.
- fuzztester 2y agoThanks.
- sshine 2y agoSince the original sed command took "Haskell" as standard input, why not: {-# LANGUAGE OverloadedStrings #-} import qualified Data.Text as T import qualified Data.Text.IO as T main :: IO () main = T.interact (T.replace "k" "sk" . T.replace "ke" "-ki")
- itishappy 2y agoDidn't think to, but that looks very slick!
- mkl 2y agosed: -e expression #1, char 5: unterminated `s' command It's like this: sed 's/find/replace/'
- fuzztester 2y agoWhoops, it was a typo. I do know how to use the sed command, at least the basics; see my previous use of it ( https://news.ycombinator.com/item?id=42084984 https://news.ycombinator.com/item?id=42084984 ). But thanks, good catch.