I wanted to Print to A pascal Triangle for a given Length.
main = do
l_str <- getLine
let l_int = read $ l_str :: Int
let why = print_row l_int 0
print why
return ()
print_row x y
| (x < y) = " "
| otherwise = (print_column y 0 ) ++ "\n" ++ print_row x (y+1)
print_column y r
| (y < r) = ""
| otherwise = (show $ fact y r ) ++ print_column y (r+1)
fact n r
| (n >= r) = truncate $ (fact' n)/((fact' (n-r))*(fact' r))
fact' n
| (n >= 0) = product [1..n]
I have checked all my functions "print_row" ,"print_column" everything works fine. I am getting this error:
PascalTriangle.hs:4:17:
No instance for (RealFrac Int) arising from a use of ‘fact’
In the expression: fact l_int 0
In an equation for ‘why’: why = fact l_int 0
In the expression:
do { l_str <- getLine;
let l_int = ...;
let why = fact l_int 0;
print why;
.... }
I am not able Understand anything about this error.The pogram works fine when I use a constant instead of l_int in line 4.Like let why = print_row 4 0.
readLnoverread <$> getLinein the future; on parse errors, the former throws an IO exception right away, instead of a difficult-to-trace pure exception at some ill-defined later point. - Daniel Wagner