[Haskell-cafe] Constraints on <$> vs <$!>

Ben hyarion at iinet.net.au
Mon Aug 10 22:32:57 UTC 2015


This doesn't buy you very much, unfortunately. (f $!) only forces its
argument if the result is ever forced. So if the implementation of
fmap doesn't force the function calls (and normally it won't, with no
possible way to use the result for anything) then f  x doesn't either;
the arguments to those calls are not forced, and so the contents of
the original structure remain unforced. For example:

Prelude> let f  x = (f $!)  x() :: Functor f => (a -> b) -> f a -> f b
Prelude> let z = const True  [undefined]z :: [Bool]
Prelude> case z of (_:_) -> "matched""matched"it :: String
Prelude> z[*** Exception: Prelude.undefined

The undefined bomb only goes off when I start to force the elements of
z; prior to that no strictness has been gained, and the list contains
a thunk as normal. In particular, this version of  wouldn't help with
the lazy IO problem described in that stackoverflow question
Christopher linked earlier.
-- Ben

----- Original Message -----
From: "Will Yager" 
To:"Christopher Allen" 
Cc:"haskell-cafe" 
Sent:Mon, 10 Aug 2015 14:30:49 -0700
Subject:Re: [Haskell-cafe] Constraints on  vs 

What about 
 f  x = (f $!)  x  
 ? 
 --Will  

On Aug 10, 2015, at 14:20, Christopher Allen  wrote:

  
http://stackoverflow.com/questions/9423622/strict-fmap-using-only-functor-not-monad
[2] seems to cover it.

On Mon, Aug 10, 2015 at 4:17 PM, Alexey Egorov  wrote:
Hello haskell ers,

 I wonder why  and  have different typeclass constraints?

 () :: Functor f => (a -> b) -> f a -> f b
 () :: Monad m => (a -> b) -> m a -> m b
 _______________________________________________
 Haskell-Cafe mailing list
Haskell-Cafe at haskell.org [4]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe [5]

-- 
Chris Allen
 Currently working on http://haskellbook.com [6]     
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe at haskell.org [7]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe [8]
 

Links:
------
[1] mailto:cma at bitemyapp.com
[2]
http://stackoverflow.com/questions/9423622/strict-fmap-using-only-functor-not-monad
[3] mailto:electreg at list.ru
[4] mailto:Haskell-Cafe at haskell.org
[5] http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
[6] http://haskellbook.com
[7] mailto:Haskell-Cafe at haskell.org
[8] http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150811/1032458c/attachment.html>


More information about the Haskell-Cafe mailing list