Idris-dev/test/reg020/reg020.idr
Edwin Brady 43127b17a7 Move Fin, Vect and So from prelude to base
They can be imported from the modules Data.Fin, Data.Vect, and Data.So
respectively.

The general thinking here is that not every program is going to need
these, and they are often used especially by newcomers in place of
something more appropriate. Also, all of them are useful for teaching,
which means it is instructive for tutorials to introduce them and have
people implement them themselves.
2014-12-31 20:18:02 +00:00

44 lines
1.1 KiB
Idris

module Main
import Data.Vect
emptyString : String
emptyString = ""
helloWorld : String
helloWorld = "hello world!"
spaceOnly : String
spaceOnly = " "
tabOnly : String
tabOnly = "\t"
linebreakOnly : String
linebreakOnly = "\n"
all : Vect 5 String
all =
[ emptyString
, helloWorld
, spaceOnly
, tabOnly
, linebreakOnly
]
lengthAll : Nat
lengthAll = Strings.length $ foldl (++) (head all) (tail all)
sumOfAllLengths : Nat
sumOfAllLengths = foldl (\ l, s => l + (Strings.length s)) (Strings.length $ head all) (tail all)
main : IO ()
main = do putStrLn $ "length of: '" ++ emptyString ++ "' is: " ++ (show $ length emptyString)
putStrLn $ "length of: '" ++ helloWorld ++ "' is: " ++ (show $ length helloWorld)
putStrLn $ "length of: '" ++ spaceOnly ++ "' is: " ++ (show $ length spaceOnly)
putStrLn $ "length of: '" ++ tabOnly ++ "' is: " ++ (show $ length tabOnly)
putStrLn $ "length of: '" ++ linebreakOnly ++ "' is: " ++ (show $ length linebreakOnly)
putStrLn $ "length of all matches sum of all lengths: " ++ (show $ lengthAll == sumOfAllLengths)