Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.42 KB | None | 0 0
  1. open System
  2. open System.IO
  3. //1
  4. type formatText=
  5.     | Simplestr of string
  6.     | Bullet_item of List<formatText>
  7.     | Bold_text of formatText
  8.     | Italic_text of formatText
  9.     | Headers of formatText
  10.  
  11. //2
  12. let rec render formatText =
  13.     match formatText with
  14.     | Simplestr(x) -> printf "%s" x
  15.     | Bullet_item(x) -> List.iter(fun elem -> printf "</> %s" "";render(elem);printf "\n") x
  16.     | Bold_text(x) -> printf "<B> %s" ""; render(x)
  17.     | Italic_text(x) -> printf "<I> %s" ""; render(x)
  18.     | Headers(x) -> printf "<H> %s" ""; render(x)
  19.  
  20. let example = Bullet_item([Bold_text(Simplestr("1TEST"));Simplestr("2TEST");Italic_text(Simplestr("3TEST"));Bullet_item([Simplestr("111TEST");Simplestr("222TEST");Simplestr("333TEST")])])
  21.  
  22. render(example)
  23. render(Headers(Italic_text(Bold_text(Simplestr("nsd")))))
  24.  //3
  25. ///////////////////////////////////////
  26. let rec min = function
  27. | [] -> failwith("error")
  28. | [x] -> (x,[])
  29. | h::t ->
  30.     let (x1,y1) = min t
  31.     if h<x1 then (h,t)
  32.     else (x1,h::y1)
  33.  
  34. min [2;3;1;3]
  35.  
  36.  
  37. let rec sort = function
  38. | [] -> []
  39. | S ->  
  40.     let (x1,y1)= min S
  41.     (x1::(sort y1))
  42.  
  43.  
  44. sort [2;3;1;3]
  45.  
  46.  
  47.  
  48. let rec F =function
  49. | [] -> []
  50. | h::t ->h:: F(List.filter (fun x->x%h<>0) t)
  51.  
  52. F [2..100]
  53.  
  54.  
  55. let Flength =
  56.     let rec len a = function
  57.     | [] -> a
  58.     | _::t -> len (a+1) t in len 0
  59.  
  60. [1;2;34;32;1;23;1;0;2]
  61. |> List.sort
  62.  
  63. List.groupBy(fun x->x%3) [1;2;3;4;5;6;7;8;9]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement