* Petr Pudlák <petr....@gmail.com> [2013-03-13 16:32:45+0100]
> If I define a function that matches on a single-constructor data type, such
> as (,), is there any reason against using ~? Like
> 
>   f (a,b) = ...
> 
> instead of
> 
>   f ~(a,b) = ...
> 
> ? I've seen that not using ~ can lead to problems sometimes, but not the
> other way around.
> 
> (Of course changing the semantics of existing functions such as `swap` is
> problematic, my question targets the problem in general.)

The usual dangers of laziness apply.

Consider, for example, the State monad. The difference between lazy and
strict State is exactly the way of pattern matching on the tuple.

Strict state monad allows you to keep your state evaluated. Lazy
doesn't.

  Prelude Control.Monad.State.Strict> flip evalState () $ (put $! undefined) >> 
return ()
  *** Exception: Prelude.undefined

  Prelude Control.Monad.State> flip evalState () $ (put $! undefined) >> return 
()
  ()

Roman

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to