[Haskell-cafe] A Question about the IO type detection

Zongzhe Yuan psyzy3 at nottingham.ac.uk
Fri Feb 13 12:00:39 UTC 2015


Hi 
i meet a problem when i was using readLn to read a int from user

my function is like that

do (some thing else that is working)
     n <- readLn
     (some thing else)
     f n x1 x2 x3 ……

f has the type of Int -> something else
because the type in this function is fixed, if the type of n is not Int, it will have exception
However i want to detect whether the user input is valid or not and i have this function

import Data.Typeable

isInteger :: Typeable a => a -> Bool
isInteger n = (typeOf n) == (typeOf (1::Int))

and add to 
do (some thing else that is working)
     n <- readLn
     if isInteger n then 
         (some thing else)
         f n x1 x2 x3 ……
     else
         (something else)
but it doesn’t work because of the reason “type has been inferred and fixed”

How could i solve this problem?

Zongzhe Yuan



This message and any attachment are intended solely for the addressee
and may contain confidential information. If you have received this
message in error, please send it back to me, and immediately delete it. 

Please do not use, copy or disclose the information contained in this
message or in any attachment.  Any views or opinions expressed by the
author of this email do not necessarily reflect the views of the
University of Nottingham.

This message has been checked for viruses but the contents of an
attachment may still contain software viruses which could damage your
computer system, you are advised to perform your own checks. Email
communications with the University of Nottingham may be monitored as
permitted by UK legislation.



More information about the Haskell-Cafe mailing list