“type error in conditional” in Haskell?

Replace putStrLn with error That will cause your program to abort completely (unless something higher level catches the exception. ).

Replace putStrLn with error. That will cause your program to abort completely (unless something higher level catches the exception. ) The problem with what you've written is that you have declared a pure type, and then are trying to do IO, which isn't allowed.

There are actually two errors in that code. You need to use error, because it has type String -> a instead of String -> IO () You apply > to Int and Int. Assuming that you want to test whether ind has length at most 3, you will have to call length.

Example: retrieve :: Int -> String -> String retrieve dat = retrieve ind dat | length ind > 3 = error "not found" | otherwise = exC ind d | d.

The second point doesn't have to be an error. He could have made Int an instance of the Ord typeclass. (but I don't think that is the case) – Jonas May 23 '09 at 17:26 forget that... he actually had an literal 3 there.. – Jonas May 23 '09 at 17:28 I think you mean making Int an instance of the Num typeclass, which would actually have worked, but would be a pretty weird thing to do.

– Ganesh Sittampalam May 23 '09 at 19:57.

You can use a pattern guard for this: retrieve :: Int -> String -> String retrieve dat = retrieve ind dat | ind.

Thanks all! Great help! – pier May 23 '09 at 18:07.

As described in Ganesh's post, you want to do IO in a pure function, which isn't possible. Ways to express your program (*you'll have to use length ind > 3 anyway) 1 Use error (best way) as shown in the other posts 2 Use pattern guards (non exhaustive patterns-exception will occur) 3 Implement the IO properly: retrieve ind dat = if ind >= 3 then do return exC ind d | d String -> IO String 4 Use Maybe to express that the computation may fail. Retrieve :: Int -> String -> Maybe String retrieve dat = retrieve ind dat | length ind > 3 = Nothing | otherwise = Just exC ind d | d.

The then branch has type IO (), the else has type String. The types of the two if branches are different and there is no way to give a type to the whole if that doesn't cause a type conflict with one of the branches.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions