idris-learning/AverageWord.idr
2021-07-08 16:30:07 +02:00

25 lines
716 B
Idris

module Main
-- import System.REPL oh god my setup is horrible
import Data.String
average : String -> Double
average str = let numWords = wordCount str
totalLength = sum (allLengths (words str)) in
cast totalLength / cast numWords
where
wordCount : String -> Nat
wordCount str = length (words str)
allLengths : List String -> List Nat
allLengths strs = map length strs
showAverage : String -> String
showAverage str = "The average word length is: " ++ show (average str) ++ "\n"
main : IO ()
main = repl "Enter a string: " showAverage
doubleSum : List Nat -> List Nat
doubleSum xs = let sum = sum xs in
[sum, sum]