[Haskell-cafe] Function Returning Type?

Stefan Holdermans stefan at cs.uu.nl
Thu May 21 15:52:00 EDT 2009


Jochem,

>>> rationals n = (putStr . unlines . map show) (take n (nub [x % y |  
>>> y <-
>>> [1..], x <- [1..y], x < y]))

>> rationals n :: Integer -> [Ratio]

> I meant "Integer -> String" obviously.

Er... what about

   rationals :: Int -> IO ()

? ;-)

To the original poster: next time, just leave the function definition  
without the signature and query GHCi for the correct type:

   Prelude> :m + List
   Prelude List> :m + Ratio
   Prelude List Ratio> let rationals n = (putStr . unlines . map show) \
     (take n (nub [x % y | y <- [1..], x <- [1..y], x < y]))
   Prelude List Ratio> :t rationals
   rationals :: Int -> IO ()

Cheers,

   Stefan




More information about the Haskell-Cafe mailing list