Sandbox

From HaskellWiki
Revision as of 17:29, 15 November 2007 by DimitryGolubovsky (talk | contribs) (Test of syntax highlight with Cyrillic function names)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Feel free to edit as you wish on this page. It is here for you to experiment with WIKI edit syntax.

section

Sandbox#secton


Pavillon Uge Uge

Matrix:

Embedded matrix:

Text taken from http://hpaste.org/3881: this wiki's syntax highlight at least does not garble the source, unlike hpaste's highlight.

module Main where

import Prelude hiding (putStrLn, print)
import System.IO.UTF8
import Data.List (intersperse, find)

type Персонаж = String
type Персонажи = [Персонаж]

едоки :: Персонажи
едоки = [ "дедка", "бабка", "внучка", "жучка", "кошка", "мышка" ]

подходы :: [ Персонажи ]
подходы = scanl позвать [] едоки
  where позвать тянущие подмога = подмога:тянущие

построились :: Персонажи -> [ (Персонаж, Персонаж) ]
построились едоки = zip едоки ("репка":едоки)

диспозиции = map (построились.reverse) подходы

описать [] = "Посадил дед репку ..."
описать диспозиция = 
  unwords ["Взялись:"
          , concat $ intersperse ", " $ map за диспозиция
          , ". Тянут-потянут -- " ++ result
          ]
  where 
    за (кто,кого) = кто ++ " за " ++ винительный_падеж кого
    винительный_падеж ы = init ы ++ "у"
    result = case find ((=="мышка").fst) диспозиция of
                  Just _  -> "вытянули репку!"
                  Nothing -> "вытянуть не могут!"

main = mapM_ putStrLn $ map описать диспозиции