[Haskell-cafe] Newbie question: inferred type

Neil Mitchell ndmitchell at gmail.com
Thu Mar 30 02:55:14 EST 2006


I think this is the monomorphism restriction, you can see more details
on the web page:

http://www.haskell.org/hawiki/MonomorphismRestriction

On 3/30/06, David Laffin <dl_y_post at yahoo.co.uk> wrote:
>
> Hi,
>
> Newbie question. Given the inferred type for square,
> the
> inferred types for quad1, quad2 and quad3 are what I
> would
> expect. Is there a straightforward explanation (i.e.
> one
> that a newbie would understand) as to why the inferred
> type
> for quad4 is less general?
>
> Regards,
> dl
>
> -- GHC Interactive, version 6.4, for Haskell 98.
>
> Prelude> let square x = x * x
> Prelude> :t square
> square :: (Num a) => a -> a
>
> Prelude> let quad1 x = square (square x)
> Prelude> :t quad1
> quad1 :: (Num a) => a -> a
>
> Prelude> let quad2 x = square $ square x
> Prelude> :t quad2
> quad2 :: (Num a) => a -> a
>
> Prelude> let quad3 x = (square . square) x
> Prelude> :t quad3
> quad3 :: (Num a) => a -> a
>
> Prelude> let quad4 = square . square
> Prelude> :t quad4
> quad4 :: Integer -> Integer
>
>
>
>
>
>
> ___________________________________________________________
> Yahoo! Photos – NEW, now offering a quality print service from just 8p a photo http://uk.photos.yahoo.com
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list