• + 1 comment

    I'm trying to explain to Haskell that a triangle is not a stright line. Can anyone help? (The output of the following code is 1 1 1 1 2 1 1 3 3 1 (without any new lines))

    -- FORMAT    
    mat v = putStr ( (show v) ++ " " ) -- print value with space     
    
    -- print tri value at coords
    pas m n
        | n == 0 = 1 
        | m == n = 1
        | otherwise = pas (m-1) (n-1) + pas (m-1) n
          
    -- print row of triangle 
    row m = mapM_ (mat . (pas m) $) [0..m]   
        
    -- print triangle until row
    tri m = mapM_ (row) [0..(m-1)] 
        
    main = do   
       m <- readLn :: IO Int
       tri m -- print tri to row m