(選択肢文字列,値)のリストをとって、ユーザーに選択肢を提示し、番号を入力して選んでもらった値を返す関数
choice :: [(String, a)] -> IO a
を作ってください。
main = putStrLn "Hello" |
{-# OPTIONS -Wall #-} | |
import Control.Monad | |
import Control.Monad.Random | |
import Data.List | |
sumDice :: (MonadRandom m) => Int -> m Int | |
sumDice n = liftM sum $ replicateM n $ getRandomR (1,6) | |
statDice :: (MonadRandom m) => Int -> m [(Int,Int)] | |
statDice n = do |
recMapM :: forall a b m. (Data a, Data b, Monad m) => (b -> m b) -> a -> m a | |
recMapM f x = do | |
let recurse = gmapM (recMapM f) x | |
case cast x of | |
Nothing -> recurse | |
Just bx -> do | |
z <- f bx | |
case cast z of | |
Nothing -> recurse | |
Just az -> return az |
#!/usr/bin/env runhaskell | |
{-# LANGUAGE NoImplicitPrelude, RecordWildCards #-} | |
{-# OPTIONS -Wall #-} | |
module Main where | |
import Data.Maybe | |
import Data.Tensor.TypeLevel | |
import GTA.Data.JoinList | |
import GTA.Core hiding (items) | |
import NumericPrelude |
main = print "hi" |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
import Control.Applicative | |
import qualified Data.Vector as V | |
import Prelude hiding (zipWith) | |
class Zippable f where | |
zipWith :: (a->b->c) -> f a -> f b -> f c |
main :: IO () | |
main = top 10 | |
top :: Int -> IO () | |
top mp = do | |
putStrLn $ "あなたのMPは:" ++ show mp | |
putStrLn "どこへ行く?" | |
choice [ ("宿屋" , inn) | |
, ("野外" , outdoor mp) ] |
gnuplot :: [String] -> IO () | |
gnuplot cmds = do | |
writeFile "tmp" $ unlines cmds | |
system "gnuplot tmp" | |
return () | |
main = do | |
gnuplot [ gnuplotSetTerm |
import Data.Typeable | |
import Test.Hspec | |
arityOf :: Typeable a => a -> Int | |
arityOf x = go $ typeOf x | |
where | |
go tr | |
| isFun $ typeRepTyCon tr = 1 + go (last $ snd $ splitTyConApp tr) | |
| otherwise = 0 |