Skip to content

Instantly share code, notes, and snippets.

@DeTeam
Created May 29, 2012 16:37
Show Gist options
  • Save DeTeam/2829451 to your computer and use it in GitHub Desktop.
Save DeTeam/2829451 to your computer and use it in GitHub Desktop.
Concept Codes
import Control.Monad
import Data.List
-- !! TODO: обернуть всю эту красоту в модуль, мб отдельные типы данных добавить
{-
Супер классная штука для формирования списка списков %)
Да, ее надо запомнить
-}
listOfLists :: Int -> [a] -> [[a]]
listOfLists n source = getStuff n [[]]
where getStuff 0 x = x
getStuff n res = do
x <- source
r <- res
let xr = x:r
getStuff n' $ return xr
where n' = n - 1
{-
Обрезаем длину справа, т.е. слева берем в два раза меньше чем есть
-}
codeUp :: [a] -> [a]
codeUp source =
let l = length source
l' = quot l 2
in
take l' source
{-
С верхнего уровня на нижний
На входе - алфавит + исходная последовательность
На выходе - родитель + дочерние
-}
codeDown :: [a] -> [a] -> [[a]]
codeDown alph source =
let l = length source
l' = l * 2
xs = listOfLists l' alph
in
do
x <- xs
return $ source ++ x
main = do
putStrLn "Works"
return ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment