mirror of
https://github.com/Noratrieb/idris-learning.git
synced 2026-01-15 13:35:01 +01:00
move and change
This commit is contained in:
parent
80aa1a2be7
commit
1330cb05e9
10 changed files with 161 additions and 142 deletions
25
chapter2/AverageWord.idr
Normal file
25
chapter2/AverageWord.idr
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
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]
|
||||
Loading…
Add table
Add a link
Reference in a new issue