Skip to content

Instantly share code, notes, and snippets.

@mmynsted
Created December 4, 2020 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmynsted/7831dbd552c1f874143c0e0d5807a4c8 to your computer and use it in GitHub Desktop.
Save mmynsted/7831dbd552c1f874143c0e0d5807a4c8 to your computer and use it in GitHub Desktop.
{-# LANGUAGE OverloadedStrings #-}
module Main
where
-- import Data.Text as T
main = putStrLn $ f 2
f :: Int -> String
f n
| n < 0 = mconcat $ take 3 x
| n > 3 = mconcat $ take 3 y
| otherwise = mconcat $ take n y <> take (3 - n) x
where
x = "&star;" : x
y = "&starf;" : y
@treblacy
Copy link

treblacy commented Dec 4, 2020

{-# LANGUAGE OverloadedStrings #-}

module Main
  where
  
import Data.Text (Text)
import qualified Data.Text.IO as T

main = T.putStrLn $ f 2


f :: Int -> Text
f n
  | n < 0 = mconcat $ take 3 x
  | n > 3 = mconcat $ take 3 y
  | otherwise = mconcat $ take n y <> take (3 - n) x
  where
    x = "&star;" : x
    y = "&starf;" : y

@mmynsted
Copy link
Author

mmynsted commented Dec 4, 2020

{-# LANGUAGE OverloadedStrings #-}

module Main
  where
  
import Data.Text as T


main = putStrLn $ unpack $ f 2


f :: Int -> Text
f n
  | n < 0 = mconcat $ Prelude.take 3 x
  | n > 3 = mconcat $ Prelude.take 3 y
  | otherwise = mconcat $ Prelude.take n y <> Prelude.take (3 - n) x
  where
    x = ("&star;" :: Text) : x
    y = ("&starf;" :: Text) : y

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment