RE: Library report examples
| The library report defines | | -- Diagonal of a square matrix | diag :: (Ix a) = Array (a,a) b - Array a b | diag x = ixmap (l,u) (\i-(i,i)) x |where ((l,l'),(u,u')) | l == l' u == u' = bounds x And that is indeed a stupid definition. It's like saying x = if x2 then 1 else 10 (the guard is really just an 'if'.) So of course l, u etc are all bottom. The guard needs to be on diag itself diag x | l==l' u==u' = ixmap ...as before where ((l,l'),(u,u')) = bounds x thanks for pointing this out | I am also curious why, for example, | | row :: (Ix a, Ix b) = a - Array (a,b) c - Array b c | row i x = ixmap (l',u') (\j-(i,j)) x where ((l,l'),(u,u')) | = bounds x | | isn't written as | | row :: (Ix a, Ix b) = a - Array (a,b) c - Array b c | row i x = ixmap (l,u) (\j-(i,j)) x where ((_,l),(_,u)) = bounds x |~~~~~~ ~~~ you can write it either way S ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
Re: Library report examples
Simon, On Tue, Nov 27, 2001 at 02:28:45AM -0800, Simon Peyton-Jones wrote: | I am also curious why, for example, | | row :: (Ix a, Ix b) = a - Array (a,b) c - Array b c | row i x = ixmap (l',u') (\j-(i,j)) x where ((l,l'),(u,u')) | = bounds x | | isn't written as | | row :: (Ix a, Ix b) = a - Array (a,b) c - Array b c | row i x = ixmap (l,u) (\j-(i,j)) x where ((_,l),(_,u)) = bounds x |~~~~~~ ~~~ you can write it either way I agree that the two are equivalent definitions, I just find the latter style easier to follow. Similarly I would write new_is = map fst new_ivs rather than new_is = [i | (i,_) - new_ivs] - maybe this is just a personal taste thing. Certainly not worth quibbling over at any rate :-) Another one for you: In 10.3 (Monad, Functions) the listFile example uses openFile where it means readFile. Another minor quibble: the use of brackets around contexts isn't consistent within the Monad section (haven't looked at the others). Thanks Ian ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
Library report examples
Hi guys, The library report defines -- Diagonal of a square matrix diag :: (Ix a) = Array (a,a) b - Array a b diag x = ixmap (l,u) (\i-(i,i)) x where ((l,l'),(u,u')) | l == l' u == u' = bounds x but ghc, hugs and nhc98 all loop (trying to get and test the value of l I believe). I am also curious why, for example, row :: (Ix a, Ix b) = a - Array (a,b) c - Array b c row i x = ixmap (l',u') (\j-(i,j)) x where ((l,l'),(u,u')) = bounds x isn't written as row :: (Ix a, Ix b) = a - Array (a,b) c - Array b c row i x = ixmap (l,u) (\j-(i,j)) x where ((_,l),(_,u)) = bounds x ~~~~~~ ~~~ Thanks Ian ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell