[Haskell-cafe] Curiose types

Rodrigo Queiro overdrigzed at gmail.com
Mon May 28 10:08:36 EDT 2007


After a little too long trying, I managed to get code from which the type
system will infer that type, without using 'undefined':

*Main> :t map
map :: ((a -> a1) -> [a]) -> [a1]

import System.IO.Unsafe
import Data.IORef
import Prelude hiding (map)
import qualified Prelude as P

coerce a = unsafePerformIO (coerce' a)
    where
        ref = unsafePerformIO $ newIORef []
        coerce' a = do
                       writeIORef ref [a]
                       b <- readIORef ref
                       return (head b)

map' a2b f = P.map a2b (f a2b)
map = map' coerce

On 27/05/07, Stefan Holdermans <stefan at cs.uu.nl> wrote:
>
> >>> map :: ((a -> b) -> [a]) -> [b]
> >>
> >> I am not following here: what do you mean? Clearly, this is not a
> >> valid typing for map. Moreover, modulo undefinedness, there are no
> >> functions with this typing.
> >
> > map _ = []
>
> Ah, well, and that one, of course... :-)
>
> Cheers,
>
>    Stefan
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070528/8c11bdc1/attachment.htm


More information about the Haskell-Cafe mailing list