Re: Homework

2003-08-21 Thread Andrew J Bromage
G'day all. On Fri, Aug 22, 2003 at 03:41:14PM +1000, [EMAIL PROTECTED] wrote: > Seeing as its thst time of year again and everyone is posting their > homework, has anyone got any good puzzles to do? > I wouldn't mind having a go at something a bit tricky. OK, here's a tricky problem. Take a lis

Re: Pascal Line in Haskell

2003-08-21 Thread Andrew J Bromage
G'day all. On Fri, Aug 22, 2003 at 09:40:12AM +1000, Job L. Napitupulu wrote: > Can anyone help me how to make a function which takes an integer n > 0 and > returns the list of integers in Line of Pascal's Triangle. For examples, > > pascalLine 4 -> [1,4,6,4,1] > pascalLine 7 -> [1,7,21,35,35,21

Homework

2003-08-21 Thread thomas_bevan
Seeing as its thst time of year again and everyone is posting their homework, has anyone got any good puzzles to do? I wouldn't mind having a go at something a bit tricky. Tom ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailm

Re: Pascal Line in Haskell

2003-08-21 Thread Ketil Z. Malde
"Job L. Napitupulu" <[EMAIL PROTECTED]> writes: > Can anyone help me how to make a function which takes an integer n > > 0 and returns the list of integers in Line of Pascal's Triangle. Yes, I imagine a lot of people can, but you're supposed to do your own homework. Here's a rough outline, thoug

Pascal Line in Haskell

2003-08-21 Thread Job L. Napitupulu
Can anyone help me how to make a function which takes an integer n > 0 and returns the list of integers in Line of Pascal's Triangle. For examples, pascalLine 4 -> [1,4,6,4,1] pascalLine 7 -> [1,7,21,35,35,21,7,1] ___ Haskell-Cafe mailing list [EMAIL P

Re: No safety in numbers

2003-08-21 Thread Konrad Hinsen
On Thursday 21 August 2003 23:39, Tom Pledger wrote: > Try > > x :: Fractional a => a > x = 0.5 > > instead. That way, the type signature is in the right place to > prevent defaulting. Right - thanks! Konrad. ___ Haskell-Cafe mailing list [EM

RE: Database interface

2003-08-21 Thread Tom Pledger
Tim Docker writes: : | Is it normal or common to support multiple simultaneous queries on | a single DB connection? In transaction processing, yes. There's an idiom where you use one query to select all the (financial) transactions in a batch, but there's so much variation in how you need to p

Re: No safety in numbers

2003-08-21 Thread Tom Pledger
Konrad Hinsen writes: | On Thursday 21 August 2003 23:23, Jon Cast wrote: | > > I can make such a declaration, but it still gets converted to Double. | > | > How are you doing this? I'm not seeing the behavior you describe. | | module Foo where | x = 0.5 :: Fractional a => a Try x ::

Re: No safety in numbers

2003-08-21 Thread David Roundy
On Thu, Aug 21, 2003 at 10:30:33PM +0200, Konrad Hinsen wrote: > I might also declare all my constants to be "Rational" and use > "fromRational", but I don't know much about the "Rational" type. Do I > have to worry about insufficient or compiler-dependent precision? I would guess that this is the

Re: No safety in numbers

2003-08-21 Thread Konrad Hinsen
On Thursday 21 August 2003 23:23, Jon Cast wrote: > > I can make such a declaration, but it still gets converted to Double. > > How are you doing this? I'm not seeing the behavior you describe. module Foo where x = 0.5 :: Fractional a => a Then I run "hugs Foo.hs" and get: Foo> :type x x :: Dou

Re: No safety in numbers

2003-08-21 Thread Jon Cast
Konrad Hinsen <[EMAIL PROTECTED]> wrote: > On Thursday 21 August 2003 22:42, Jon Cast wrote: > > > > (or any other type I declare it to be). > > > > Right. But: you can declare it to have type Fractional alpha => > > alpha, which is the same type the constant has in the middle of an > > expressio

Re: Monads and Maybe

2003-08-21 Thread Jon Cast
> tor 2003-08-21 klockan 22.26 skrev Jon Cast: > > Yes. Many complicated proposals have been made, but there's a > > straightforward, general mechanism: > > > > > addMaybe :: Num alpha => Maybe alpha -> Maybe alpha -> Maybe alpha > > > addMaybe a b = a >>= \x -> > > >b >>= \y -> >

Re: No safety in numbers

2003-08-21 Thread Konrad Hinsen
On Thursday 21 August 2003 22:42, Jon Cast wrote: > > (or any other type I declare it to be). > > Right. But: you can declare it to have type Fractional alpha => alpha, > which is the same type the constant has in the middle of an expression. I can make such a declaration, but it still gets conv

Re: Monads and Maybe

2003-08-21 Thread Doaitse Swierstra
On dinsdag, aug 19, 2003, at 15:09 Europe/Amsterdam, C T McBride wrote: Hi As an example, I'll use the Maybe monad. Suppose I want to write code to handle experimental data, in which there might be missing values. I might then decide to represent measurements by data of type "Maybe Double", wi

Re: Monads and Maybe

2003-08-21 Thread Martin Norbäck
tor 2003-08-21 klockan 22.26 skrev Jon Cast: > Yes. Many complicated proposals have been made, but there's a > straightforward, general mechanism: > > > addMaybe :: Num alpha => Maybe alpha -> Maybe alpha -> Maybe alpha > > addMaybe a b = a >>= \x -> > >b >>= \y -> > >

Re: No safety in numbers

2003-08-21 Thread Jon Cast
Konrad Hinsen <[EMAIL PROTECTED]> wrote: > I am trying to write a larger piece of code using only type > constraints for all the numbers, not specific types, in order to be > able to choose the precision as late as possible. Good for you! (I say this in all seriousness.) > This works rather wel

Re: Monads and Maybe

2003-08-21 Thread Jon Cast
Konrad Hinsen <[EMAIL PROTECTED]> wrote: > I have been following the recent "Monad tutorial" discussion with > interest, and even read the tutorial, which is a useful addition to > the existing Haskell documentation. So useful in fact that it raises a > question... > > The whole monad mechanism

No safety in numbers

2003-08-21 Thread Konrad Hinsen
I am trying to write a larger piece of code using only type constraints for all the numbers, not specific types, in order to be able to choose the precision as late as possible. This works rather well (something I can't say of many other languages), but one problem I keep running into is constan

Re: recursion

2003-08-21 Thread Keith Wansbrough
> > hi guys, > may i know how to use recursive in a function. for example i have a function lets > call it old which accept [[Bool]]->[(Int),(Int)]->(Int,Int) and return > [(Int),(Int)] > and now i have another function lets say its called new, which calls the previous > function and new will r

Re: haskell reify, was sequencing data structures

2003-08-21 Thread Alastair Reid
> Things that seem important (to me) are: > >- Do you want to observe cycles and or sharing? Yes. > Of course this is very hard to do because of garbage collection. Only in the sense that holding onto an object pointer to detect a cycle might cause you to hold onto the object too - ca

Re: Monads and Maybe

2003-08-21 Thread C T McBride
Hi > > Or, more generally, > > > > infixl 9 <$> > > > > (<$>) :: Monad m => m (s -> t) -> m s -> m t > > mf <$> ms = > > do f <- mf > >s <- ms > >return (f s) > > or just liftM2 ($) > or just ap OK, I'm a bad citizen and I never look things up in the library. If it isn't

RE: Database interface

2003-08-21 Thread Bayley, Alistair
> From: Tim Docker [mailto:[EMAIL PROTECTED] > > > It also has the benefit that the function you pass to doquery can > make > > other calls to doquery, without mucking up the 'current row' state. > > There would be one current row per Cursor, not one per Process. > > Is it normal or common to s

RE: Database interface

2003-08-21 Thread Tim Docker
Tom Pledger wrote: > How about introducing a Cursor abstract data type? > > doquery :: Process -> String -> b -> (Cursor -> b -> IO (b, Bool)) >-> IO b > stringv :: Cursor -> CInt -> IO String > doublev :: Cursor -> CInt -> IO Double > intv:: Cursor -> C

recursion

2003-08-21 Thread Tn X-10n
hi guys, may i know how to use recursive in a function. for example i have a function lets call it old which accept [[Bool]]->[(Int),(Int)]->(Int,Int) and return [(Int),(Int)] and now i have another function lets say its called new, which calls the previous function and new will recursively check