[Solved] Haskell join function inputs in list in specific order

Well since you got it working without the starting/ending point. An easy way to complete would be use your function but add the starting/ending point in the list in an inner function. So your interface is still same. Another way using recursion, pattern matching and guards is: — assuming the inputs to be int as … Read more

[Solved] F1 Results with Haskell

You have a constant for what the scoring is scoring :: [Int] scoring = [25, 18, 15, 12, 10, 8, 6, 4, 2, 1] Then you need a way for pairing up a driver with the score they got. Whenever you’re pairing two things in Haskell, the canonical choice is to use a tuple. The … Read more

[Solved] Summing the digits of a very large number [closed]

This would be a complete implementation in Haskell import Data.List.Split (chunksOf) import Data.List import Data.Char (digitToInt) main :: IO () main = do digits <- map digitToInt <$> readFile “pifile.txt” let summator = foldl1′ (zipWith (+)) . chunksOf 4 print $ summator digits I will update this with some explanation later this day. Update @Comments … Read more

[Solved] Maximum tree depth in Haskell

You would want to write a recursive function to do this. For each Tree constructor, you’ll need a different case in your function. To start with, you know that the depth of any Leaf is 1, so maxDepth :: Tree -> Int maxDepth (Leaf _) = 1 maxDepth (Branch2 c left right) = maximum [???] … Read more

[Solved] parse error in haskell

additionally you want to separate the bmi-calculator from the main function as it is a pure function without any side-effects main :: IO () main = do putStrLn “Please Input your weight” w <- getLine let weight = read w :: Float putStrLn “Please Input your height” h <- getLine let height = read h … Read more

[Solved] Haskell Zip Parse Error

printList :: IO () printList = do putStrLn “Printed Combined List” zip [NameList][PriorityList] There are many things wrong with this code. The parse error you are seeing is because the do block is not properly aligned. The zip on the last line must line up with the putStrLn on the line before. So either printList … Read more

[Solved] Haskell, tuple (double, string) [closed]

You can implement it using mapM_/traverse_ or the flipped argument versions: forM_/for_. I prefer for_ since it looks more like the “enhanced for-loop” from languages like Java. import Data.Foldable (for_) myPutStr :: [(Double,String)] -> IO () myPutStr vals = do for_ vals $ \(num, str) -> do putStr str putStr “: ” print (num * … Read more