learning F#, it seems pretty cool, favourite functional language so far.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12345678910111213141516171819202122232425
  1. module KindergartenGarden
  2. open System
  3. type Plant =
  4. | Grass
  5. | Clover
  6. | Radishes
  7. | Violets
  8. let getNumFromName (student: string) = int (student.[0]) - int ('A')
  9. let getPlantChars (row: string) num =
  10. [ for c in (row.[(num * 2)..(num * 2 + 1)]) -> c ]
  11. let plants (diagram: string) (student: string) =
  12. diagram.Split [| '\n' |] // Split the rows up
  13. |> Seq.map (fun i -> (getPlantChars i (getNumFromName student))) // Go over each row getting the child's plants
  14. |> Seq.reduce List.append // This flattens the list becuase before this it looks like [['a', 'b']['c', 'd']] and we want ['a', 'b', 'c', 'd']
  15. |> List.map (fun i -> // Now for each plant character return the relavant plant type
  16. match i with
  17. | 'G' -> Grass
  18. | 'C' -> Clover
  19. | 'R' -> Radishes
  20. | _ -> Violets)