Skip to content

Instantly share code, notes, and snippets.

@tokiwoousaka
Last active August 29, 2015 14:10
Show Gist options
  • Save tokiwoousaka/1a06887f58e7465ef6e9 to your computer and use it in GitHub Desktop.
Save tokiwoousaka/1a06887f58e7465ef6e9 to your computer and use it in GitHub Desktop.
SeasonalFruitsを「SeasonとFruitのタプル」のリストと定義、即ち、季節と果物の直積の部分集合を表す。SeasonalFruits -> [Season] という型から、query関数はSeasonalFruitsから季節の部分集合への写像であると読める。
module Main where
import Control.Monad
type Season = String
type Fruit = String
type SeasonalFruits = [(Season, Fruit)]
dt :: SeasonalFruits
dt =
[ ("春", "いちご")
, ("夏", "もも")
, ("春", "りんご")
, ("冬", "みかん")
]
query :: SeasonalFruits -> [Season]
query list = do
(season, fruit) <- list
guard $ fruit == "もも"
return season
main :: IO ()
main = mapM_ putStrLn (query dt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment