[Haskell-beginners] Re: [Haskell-cafe] What is an "expected type" ...

michael rice nowgate at yahoo.com
Sun Jun 28 12:39:37 EDT 2009


How else? ;-)

Thanks,

Michael

--- On Sun, 6/28/09, Brandon S. Allbery KF8NH <allbery at ece.cmu.edu> wrote:

From: Brandon S. Allbery KF8NH <allbery at ece.cmu.edu>
Subject: Re: [Haskell-cafe] What is an "expected type" ...
To: "michael rice" <nowgate at yahoo.com>
Cc: "Brandon S. Allbery KF8NH" <allbery at ece.cmu.edu>, "Joe Fredette" <jfredett at gmail.com>, beginners at haskell.org, "Haskell Cafe mailing list" <haskell-cafe at haskell.org>
Date: Sunday, June 28, 2009, 12:06 PM

On Jun 28, 2009, at 12:02 , michael rice wrote:dec2bin :: Integer -> [Integer]
dec2bin n = dec2bin' n []
            where dec2bin' n acc
                    | n == 0 = acc
                    | otherwise = let r = rem n 2
                                      m = div (n - r) 2
                                  in dec2bin' m (r : acc)

is there any way to assign a type signature to the helper function?

Same way you do for a top level binding:
dec2bin :: Integer -> [Integer]
dec2bin n = dec2bin' n []
            where dec2bin' :: Integer -> [Integer] -> [Integer]
                  dec2bin' n acc
                    | n == 0 = acc
                    | otherwise = let r = rem n 2
                                      m = div (n - r) 2
                                  in dec2bin' m (r : acc)
 -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.comsystem administrator [openafs,heimdal,too many hats] allbery at ece.cmu.eduelectrical and computer engineering, carnegie mellon university    KF8NH
 



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20090628/f1f2fb7e/attachment.html


More information about the Beginners mailing list