Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Html exposing (Html, text, div, input)
- import Html.Events exposing (onInput)
- import Html.Attributes exposing (id)
- import Tuple exposing (second)
- import String exposing (toList, fromList, fromChar)
- import List exposing (tail, head, member, map, member)
- import Char exposing (isUpper, toUpper, toLower)
- type alias Model = (String, String)
- model: Model
- model = ("", "")
- type Msg = Convert String
- isVowel : Char -> Bool
- isVowel c = member (toUpper c) ['A', 'E', 'I', 'O', 'U']
- pigLatinize : String -> String
- pigLatinize orig =
- case (map toLower <| toList orig) of
- [] -> ""
- [a] -> (fromChar <| toUpper a) ++ "ay"
- (hd :: snd :: lst) ->
- if isVowel <| hd then
- orig ++ "ay"
- else
- fromList <| [toUpper <| snd] ++ lst ++ [hd] ++ ['a', 'y']
- update : Msg -> Model -> Model
- update mg mo =
- case mg of
- Convert str -> (str, pigLatinize str)
- view : Model -> Html Msg
- view model = div[(id "outer-div")][
- input[(id "input-field"), (onInput Convert)][],
- text("The piglatinized version is " ++ (second model))]
- main : Program Never Model Msg
- main = Html.beginnerProgram {
- model = model,
- view = view,
- update = update}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement