Skip to content

Instantly share code, notes, and snippets.

@pogin503
Created May 6, 2012 02:49
Show Gist options
  • Select an option

  • Save pogin503/2607186 to your computer and use it in GitHub Desktop.

Select an option

Save pogin503/2607186 to your computer and use it in GitHub Desktop.
-- import Control.Monad
import Data.Int
-- cubed :: String -> Integer
-- cubed x = product [x, x, x]
import Data.Set
import Text.Printf (printf)
cubed :: Int -> Int
cubed x = x * x * x
-- rInt :: String -> Int
-- rInt = getLine
stringToInt :: String -> Int
stringToInt str = read str :: Int
-- @see http://www.shido.info/hs/haskell8.html
-- whole function to convert string to Maybe Int
-- str2int :: String -> Maybe Int
-- str2int "" = Nothing
-- str2int str = iter (0, str)
-- where iter (i, "") = Just i
-- iter (i, cs) = let p = s2i (i, cs)
-- in if p == Nothing
-- then Nothing
-- else p >>= iter
main = do
s <- getLine
-- putStrLn $ cubed s
-- putStrLn (cubed s :: Int)
-- putStrLn (show (cubed s))
-- mapM print (cubed s)
-- cubed ((read :: String -> Int) s)
printf "%s\n" s
let s1 = stringToInt s
let s2 = cubed s1
printf "%d\n" s2
-- s3 <- read `fmap` readLn :: IO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment