Skip to content

Instantly share code, notes, and snippets.

@nushio3
nushio3 / sugoi07.md
Last active December 15, 2015 11:29

小問1

(選択肢文字列,値)のリストをとって、ユーザーに選択肢を提示し、番号を入力して選んでもらった値を返す関数

choice :: [(String, a)] -> IO a

を作ってください。

@nushio3
nushio3 / wasshoi.hs
Created November 28, 2012 16:31
test
{-# 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
@nushio3
nushio3 / gist:4162351
Created November 28, 2012 16:27
how to treat zippable objects as applicatives.
main = print "hi"
#!/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
@nushio3
nushio3 / MainRand.hs
Created January 5, 2012 08:25
これはどうにかなりませんかねえ ref: http://qiita.com/items/1580
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
@nushio3
nushio3 / Dice.hs
Created January 5, 2012 07:11
サイコロを振るモナド ref: http://qiita.com/items/1579
{-# 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
main = putStrLn "Hello"