Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open System
- type LineElement =
- |Word of string
- |Space of int
- type NewLineElement = Line of (LineElement list)*int*int
- let nspace n =
- let rec nspace' n str =
- match n with
- |0->str
- |_->nspace' (n-1) (str+" ")
- nspace' n ""
- let list = [Word("jgxzczx") ; Word ("svyaza"); Word ("korova"); Word ("at"); Word("let"); Word("kok"); Word("s"); Word("ere"); Word("oblom"); Word("Kirovreporting")]
- let divide list num =
- let rec divide' list num acc list' list'' numwd =
- match list with
- |hd::tl ->
- match hd with
- |Word a when (acc+String.length a<=num) -> divide' tl num (acc+String.length a+1) (list') (list''@[Space(1)]@[Word(a)]) (numwd+1)
- |Word a when (acc+String.length a>num)-> divide' tl num (String.length a) (list'@ [Line(list'', acc, numwd+1)]) ([Word(a)]) (0)
- |[]->list'@[Line(list'',acc, numwd+1)]
- divide' list num 0 [] [] 0
- let rec alignleft list num =
- match list with
- |hd::tl->
- match hd with
- |Line(list',a, numwd)->[Line(list'@[Space(num-a)], a, numwd)] @ alignleft tl num
- |[]->[]
- let rec aligncentre list num =
- match list with
- |hd::tl->
- match hd with
- |Line(list',a, numwd)->[Line([Space((num-a)%2 + (num-a)/2)]@list'@[Space((num-a)/2)], a, numwd)] @ aligncentre tl num
- |[]->[]
- let rec alignright list num =
- match list with
- |hd::tl->
- match hd with
- |Line(list',a, numwd)->[Line([Space(num-a)]@list', a, numwd)] @ alignright tl num
- |[]->[]
- let newline list numwd numlet num =
- let rec newline' list numwd numlet num listnak=
- match list with
- |(Space k)::tl-> newline' tl numwd numlet num (Space ((num-numlet)/numwd)::listnak)
- |(Word k)::tl -> newline' tl numwd numlet num (Word k::listnak)
- |[]->listnak
- Line(newline' list numwd numlet num [], numlet, numwd)
- let rec alignwidth list num =
- match list with
- |hd::tl->
- match hd with
- |Line(list',a, numwd)-> (newline list' numwd a num)::(alignwidth tl num)
- |[]->[]
- let rec printline line=
- match line with
- |Space(k)::tl->printf "%A" (nspace k); printline tl
- |Word(k)::tl->printf "%A" k; printline tl
- |[]->printfn ""
- let rec printtext list =
- match list with
- Line(list', a, b)::tl->printline list'; printtext tl
- |[]->printfn "";[1]
- let sc = divide list 20
- let m = alignwidth sc 20
- let r = printtext m
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement