This is taken from HackerRank, which I hope is okay.
I've been playing around with Haskell and I haven't really been able to find anything that really goes beyond toy examples in terms of how to write a readable, well-structured program. Several parts of this seem messy but I guess I don't really know any better. Anyway, here's my code, which works (or at least passes all the unit tests supplied at HackerRank).
import Control.Monad -- Given a list, return the pairs of consecutive elements in the list consec :: [a] -> [(a,a)] consec xs = zip xs (drop 1 (cycle xs)) -- Given a list of two elements, return a 2-tuple of the elements make2Tuple :: [a] -> (a, a) make2Tuple [x, y] = (x, y) -- Apply a given function to the first element of a list applyToFirst :: (a -> a) -> [a] -> [a] applyToFirst _  =  applyToFirst f (x:xs) = (f x):xs -- Split a list at a specified delimiter split :: Eq a => a -> [a] -> [[a]] split _  = [] split y (x:xs) | (x == y) = :(split y xs) | (x /= y) = applyToFirst (x:) (split y xs) -- Convert a string to a list of integers stringToInts :: [Char] -> [Int] stringToInts = map (read :: [Char] -> Int) . (split ' ') -- Action that reads in a 2-tuple of integers getInt2Tuple :: IO (Int, Int) getInt2Tuple = fmap (make2Tuple . stringToInts) getLine euclideanDistance :: ((Int, Int), (Int, Int)) -> Double euclideanDistance ((x1, y1), (x2, y2)) = sqrt(fromIntegral((y2-y1)*(y2-y1) + (x2-x1)*(x2-x1))) computePerimeter :: [(Int, Int)] -> Double computePerimeter xs = sum (map euclideanDistance (consec xs)) main :: IO () main = (fmap computePerimeter (fmap (read :: [Char] -> Int) getLine >>= (\n -> replicateM n getInt2Tuple))) >>= print
4 (0, 0) (0, 1) (1, 1) (1, 0)
The input says that this polygon has four vertices, and then lists the vertices of a unit square. The perimeter of a unit square is 4 (one unit per edge times four edges), which is what's output.