[Haskell-cafe] what does the '~' mean ?
Ryan Ingram
ryani.spam at gmail.com
Tue Apr 20 17:39:27 EDT 2010
On Thu, Apr 15, 2010 at 10:59 PM, zaxis <z_axis at 163.com> wrote:
>
> instance (BinaryDefer a, BinaryDefer b) => BinaryDefer (a,b) where
> put (a,b) = put2 a b
> get = get2 (,)
> size x = let ~(a,b) = x in size a + size b
> putFixed (a,b) = putFixed2 a b
> getFixed = getFixed2 (,)
>
> in `size` function, what does the `~` mean ?
This is kind of a funny question, because in this case the ~ doesn't
mean anything at all. Pattern matches in let are automatically
irrefutable/lazy.
A better way to write this is
size ~(a,b) = size a + size b
which is equivalent to
size x = size a + size b where
(a,b) = x
which is equivalent to
size x = let (a,b) = x in size a + size b
which is equivalent to
size x = let
a = case x of (v,_) -> v
b = case x of (_,v) -> v
in size a + size b
If a or b never get evaluated, the case statements (which will fail on
bottom values) don't happen.
More information about the Haskell-Cafe
mailing list