On Thu, Apr 15, 2010 at 10:59 PM, zaxis <[email protected]> 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.
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe