[Haskell-cafe] do we have something like isDefined or isNull in Haskell?

2006-06-15 Thread Vladimir Portnykh
Suppose there is a data definition in Haskell: data MyType = MyType { date :: Double, weight :: Double, height:: Double } deriving (Eq, Ord, Show) Is it possible to check if the field height, for example, is filled

Re: [Haskell-cafe] do we have something like isDefined or isNull in Haskell?

2006-06-15 Thread Bryan Burgers
On 6/15/06, Vladimir Portnykh [EMAIL PROTECTED] wrote: Suppose there is a data definition in Haskell: data MyType = MyType { date :: Double, weight :: Double, height:: Double } deriving (Eq, Ord, Show) Is it possible to

Re: [Haskell-cafe] do we have something like isDefined or isNull in Haskell?

2006-06-15 Thread Duncan Coutts
On Thu, 2006-06-15 at 12:43 +0100, Vladimir Portnykh wrote: Suppose there is a data definition in Haskell: data MyType = MyType { date :: Double, weight :: Double, height:: Double } deriving (Eq, Ord, Show) Is it possible to

[Haskell-cafe] Rotating matrices

2006-06-15 Thread Thomas Sutton
Dear list, I'm currently engaged in an attempt to wrap my head around type arithmetic. To make sure that I've understood, I plan to write a few operations on matrices a la Oleg's Number Parameterised Types. Before I get down to it, I've been making sure I know how to implement the

Re: [Haskell-cafe] Rotating matrices

2006-06-15 Thread Henning Thielemann
On Thu, 15 Jun 2006, Thomas Sutton wrote: Today I've been looking at rotating matrices, i.e: taking a column-wise matrix and making it row-wise and, in the process, swapping the dimensions (thus a 3*2 matrix becomes a 2*3 matrix). You mean 'matrix transposition' which is available as

Re: [Haskell-cafe] Rotating matrices

2006-06-15 Thread Stefan Holdermans
Thomas, rotate' :: [[a]] - [[a]] rotate' [] = [] rotate' xs = (map (head) xs ):(rotate' $ filter (not . null) $ map (tail) xs) which seems to work just fine. While this solution is adequate (it seems to work for infinite structures as well, which is good), I originally set out to

[Haskell-cafe] Receiving multicasts

2006-06-15 Thread Rich Neswold
Hello, Has anyone figured out a way to receive multicasts in a Haskell program? It doesn't appear that Network.Socket.setSocketOption provides enough information to join a multicast address. Any information would be appreciated. -- Rich AIM : rnezzy ICQ : 174908475

[Haskell-cafe] what do you think of haskell ? (yes, it's a bit general ...:)

2006-06-15 Thread minh thu
hi all folks, i'm diving into haskell for more than one year now. the reason for that is just that i like haskell. (i'm a computer science student) but i consider to move back to c/c++. here are my thoughts. i've no specific question but i'd like to have your opinion. here we go: haskell is

[Haskell-cafe] Fibonacci numbers generator in Haskell

2006-06-15 Thread Vladimir Portnykh
Fibonacci numbers implementations in Haskell one of the classical examples. An example I found is the following: fibs :: [Int] fibs = 0 : 1 : [ a + b | (a, b) - zip fibs (tail fibs)] To get the k-th number you do the following: Result = fibs !! k It is elegant but creates a list of all

Re: [Haskell-cafe] what do you think of haskell ? (yes, it's a bit general ...:)

2006-06-15 Thread Neil Mitchell
Hi Minh, When I write Haskell, its because I want to write the code quickly, not because I want it to run quickly. GHC is a wonderful compiler and makes things go fast, but Hugs is faster at compiling, so I always use Hugs (WinHugs in fact). If your focus is on things going fast, then with

Re: [Haskell-cafe] Fibonacci numbers generator in Haskell

2006-06-15 Thread Spencer Janssen
Here's some code I wrote a while back for computing the nth Fibonacci number. It has O(log n) time complexity rather than O(n). It isn't the most elegant example, but it should be one of the fastest approaches. import Data.Bits (shiftR, xor, (.|.), (..)) import Data.Word (Word32) fibo ::

Re: [Haskell-cafe] what do you think of haskell ? (yes, it's a bit general ...:)

2006-06-15 Thread minh thu
hi, thanks for your answer. the kind of thing i want to do : computer graphics programming. so array is better than list (no ?) to represent images ... bye vo minh thu (hey, my last name is VO, and my first name is Thu, not Minh :) 2006/6/15, Neil Mitchell [EMAIL PROTECTED]: Hi Minh, When I

Re: [Haskell-cafe] what do you think of haskell ? (yes, it's a bit general ...:)

2006-06-15 Thread Sebastian Sylvan
On 6/15/06, minh thu [EMAIL PROTECTED] wrote: hi, thanks for your answer. the kind of thing i want to do : computer graphics programming. so array is better than list (no ?) to represent images ... This may not be very helpful, but I would say that an Image is neither a list nor an array -

Re: [Haskell-cafe] what do you think of haskell ? (yes, it's a bit general ...:)

2006-06-15 Thread Joel Reymont
On Jun 15, 2006, at 6:18 PM, Sebastian Sylvan wrote: This may not be very helpful, but I would say that an Image is neither a list nor an array - it's a function! :-) How exactly do you manipulate the bits and bytes of a function? -- http://wagerlabs.com/

Re: [Haskell-cafe] what do you think of haskell ? (yes, it's a bit general ...:)

2006-06-15 Thread minh thu
right :) i had to say a discrete image ... or a raster, or an *array* of pixels ! sylvan, it must be nice to talk with you (an funny) about haskell and cg :) mt 2006/6/15, Sebastian Sylvan [EMAIL PROTECTED]: On 6/15/06, minh thu [EMAIL PROTECTED] wrote: hi, thanks for your answer. the kind

Re: [Haskell-cafe] what do you think of haskell ? (yes, it's a bit general ...:)

2006-06-15 Thread Sebastian Sylvan
On 6/15/06, Joel Reymont [EMAIL PROTECTED] wrote: On Jun 15, 2006, at 6:18 PM, Sebastian Sylvan wrote: This may not be very helpful, but I would say that an Image is neither a list nor an array - it's a function! :-) How exactly do you manipulate the bits and bytes of a function? Well I

Re: [Haskell-cafe] do we have something like isDefined or isNull in Haskell?

2006-06-15 Thread Clifford Beshers
Duncan Coutts wrote: On Thu, 2006-06-15 at 13:11 +0100, Duncan Coutts wrote: then you can construct your records using: foo = default { weight = 3.2 } Oops, as David House pointed out to me that should of course be foo = default { weight = Just 3.2 } I think the

Re: [Haskell-cafe] what do you think of haskell ? (yes, it's a bit general ...:)

2006-06-15 Thread Henning Thielemann
On Thu, 15 Jun 2006, minh thu wrote: * randomIO side-effect is nicely resolved with monad. and you have to thread your state. if you're writing your monad or use a transformer, things are quite explicitly (even if it's implicit in the do notation) threaded. You know that random generators

Re: [Haskell-cafe] Fibonacci numbers generator in Haskell

2006-06-15 Thread Henning Thielemann
On Thu, 15 Jun 2006, Vladimir Portnykh wrote: Fibonacci numbers implementations in Haskell one of the classical examples. An example I found is the following: fibs :: [Int] fibs = 0 : 1 : [ a + b | (a, b) - zip fibs (tail fibs)] To get the k-th number you do the following: Result = fibs !!

Re: [Haskell-cafe] Everything but the lazyness - idea for force/delay lists

2006-06-15 Thread Brian Hulley
minh thu wrote: hi in fact, i think that for a while ... moreover, i thought to translate to some kind of readable c (because there s so much c libs all around). i think it's even possible to retain laziness where it's ok ( for data structure essentially). Hi Thu - Someone pointed out

Re: [Haskell-cafe] what do you think of haskell ? (yes, it's a bit general ...:)

2006-06-15 Thread minh thu
hi, yes i know about that, but i was talking about randomIO which breaks that view; and i find that quite weird for a 'clean' language. * another thing i remember now : binary io. there are some libraries but it's not really standard. and it's weird to learn all (well, or just one) that

Re: [Haskell-cafe] do we have something like isDefined or isNull in Haskell?

2006-06-15 Thread Bryan Burgers
Vladimir, I think you forgot to put Haskell-cafe as a recipient of this email, so first I'll repost what you wrote. On 6/15/06, Vladimir Portnykh [EMAIL PROTECTED] wrote: many thanks. i have the follwoing code: module MyType (DataContainer(..)) where import Maybe data DataContainer =

Re: [Haskell-cafe] Learning C after Haskell

2006-06-15 Thread Graham Klyne
I did the transition the other way, and even now the real-world keeps me using more C-like languages (Java, Python). Unlike the transition from imperative languages to Haskell, I don't think there's much you have to unlearn or rethink. But I suspect you may feel a degree of frustration at how

Re: [Haskell-cafe] what do you think of haskell ? (yes, it's a bit general ...:)

2006-06-15 Thread Brian Hulley
minh thu wrote: hi all folks, i'm diving into haskell for more than one year now. the reason for that is just that i like haskell. (i'm a computer science student) but i consider to move back to c/c++. There is also OCaml and SML, both of which have freely available compilers to generate

Re: [Haskell-cafe] what do you think of haskell ? (yes, it's a bit general ...:)

2006-06-15 Thread Udo Stenzel
minh thu wrote: but i consider to move back to c/c++. I'm led to believe that you just haven't got the hang of the things that just aren't there in C, such as Monads and higher order functions. So you cannot yet see what you would miss in C. (And I guess, you're not feeling at home in C++

Re: [Haskell-cafe] do we have something like isDefined or isNullin Haskell?

2006-06-15 Thread Brian Hulley
On Thursday, June 15, 2006 8:07 PM Clifford Beshers wrote: On another note, who picked the word `Just' for this type and how did we end up with Some x | None in O'Caml and Just x | Nothing in Haskell? I've always thought this is one of the most charming things about Haskell, along with the

Re: [Haskell-cafe] Fibonacci numbers generator in Haskell

2006-06-15 Thread ajb
G'day all. Quoting Vladimir Portnykh [EMAIL PROTECTED]: I wrote my own Fibonacci numbers generator: fib :: Int - [Int] fib 0 = [0,0] fib 1 = [1,0] fib n = [sum prevFib, head prevFib] where a = fib (n - 1) To get the k-th number you do the following: result = head (fib k) [...] Can

Re: [Haskell-cafe] Fibonacci numbers generator in Haskell

2006-06-15 Thread Mathew Mills
How about the closed form ;) -- fib x returns the x'th number in the fib sequence fib :: Integer - Integer fib x = let phi = ( 1 + sqrt 5 ) / 2 in truncate( ( 1 / sqrt 5 ) * ( phi ^ x - phi' ^ x ) ) Seems pretty quick to me, even with sqrt and arbitrarily large numbers. On

Re: [Haskell-cafe] Fibonacci numbers generator in Haskell

2006-06-15 Thread Doug Quale
Mathew Mills [EMAIL PROTECTED] writes: -- fib x returns the x'th number in the fib sequence fib :: Integer - Integer fib x = let phi = ( 1 + sqrt 5 ) / 2 phi' = ( 1 - sqrt 5 ) / 2 in truncate( ( 1 / sqrt 5 ) * ( phi ^ x - phi' ^ x ) ) -- Seems pretty quick to me, even