Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let Words = ["test"; "sts"; "third"; "1"; "4815"; "ucwie"; "word"; "a"]
- type lineElement =
- |Word of string
- |Space of int
- let rec lineCreator' lineslist list length line free =
- match list with
- |hd::tl ->
- let element = Word(hd)
- if String.length hd + 1 <= free then
- let line' = line @ [element]
- let line'' = line' @ [Space(1)]
- let NowFree = free - String.length hd - 1
- lineCreator' lineslist tl length line'' NowFree
- else
- let lineslist' = lineslist @ [line]
- let line' = [element]
- let line'' = line' @ [Space(1)]
- let NowFree = length - String.length hd - 1
- lineCreator' lineslist' tl length line'' NowFree
- |_-> lineslist
- //отличная идея: чтобы избавиться от лишнего пробела в конце строки, перевернем ее, откусим голову,
- //перевернем снова! (рука не поднялась реализовывать)
- let lineCreator listWords length = lineCreator' [] listWords length [] length //вместо обертки
- let abc = lineCreator Words 6 //пока работает только первая функция
- //пробуем печатать
- let rec matchingLine line =
- match line with
- |element::lineTail ->
- match element with
- |Space(k)::tl ->
- printf " lol"
- matchingLine lineTail
- |Word(k)::tl ->
- printf " word"
- matchingLine lineTail
- |_ -> ()
- |_-> ()
- let rec printLines linesList =
- match linesList with
- |line::tl ->
- matchingLine line
- printfn "|"
- printLines tl
- |_ -> ()
- printLines abc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement