Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. import Html exposing (Html, text, div, input)
  2. import Html.Events exposing (onInput)
  3. import Html.Attributes exposing (id)
  4. import Tuple exposing (second)
  5. import String exposing (toList, fromList, fromChar)
  6. import List exposing (tail, head, member, map, member)
  7. import Char exposing (isUpper, toUpper, toLower)
  8.  
  9. type alias Model = (String, String)
  10.  
  11. model: Model
  12. model = ("", "")
  13.  
  14. type Msg = Convert String
  15.  
  16. isVowel : Char -> Bool
  17. isVowel c = member (toUpper c) ['A', 'E', 'I', 'O', 'U']
  18.  
  19. pigLatinize : String -> String
  20. pigLatinize orig =
  21. case (map toLower <| toList orig) of
  22. [] -> ""
  23. [a] -> (fromChar <| toUpper a) ++ "ay"
  24. (hd :: snd :: lst) ->
  25. if isVowel <| hd then
  26. orig ++ "ay"
  27. else
  28. fromList <| [toUpper <| snd] ++ lst ++ [hd] ++ ['a', 'y']
  29.  
  30. update : Msg -> Model -> Model
  31. update mg mo =
  32. case mg of
  33. Convert str -> (str, pigLatinize str)
  34.  
  35. view : Model -> Html Msg
  36. view model = div[(id "outer-div")][
  37. input[(id "input-field"), (onInput Convert)][],
  38. text("The piglatinized version is " ++ (second model))]
  39.  
  40. main : Program Never Model Msg
  41. main = Html.beginnerProgram {
  42. model = model,
  43. view = view,
  44. update = update}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement