POV-Ray : Newsgroups : povray.off-topic : Try Haskell Server Time
4 Sep 2024 21:18:33 EDT (-0400)
  Try Haskell (Message 51 to 60 of 62)  
<<< Previous 10 Messages Goto Latest 10 Messages Next 2 Messages >>>
From: scott
Subject: Re: Try Haskell
Date: 15 Mar 2010 11:19:07
Message: <4b9e4feb$1@news.povray.org>
> I'm pretty sure if I tried to explain the rules of gravitation to a girl, 
> I wouldn't _have_ a girlfriend for very long...

She wasn't interested in space before she met me, it's only when she saw 
Saturn through the telescope that she thought it was really cool and started 
to read a lot about it - she asks lots of questions.  But it's a very fine 
line to tread, if I try to make things too simple I get the "I'm not dumb - 
god who did you date before me" line, but go too far the other way and you 
get "ok i don't understand, i give up, don't bother".

> Heh, oh well. I was expecting the reply to be "I can't think of anything 
> that Haskell would be useful for". ;-)

Well that too :-)  I guess I just don't do much of the sort of stuff Haskell 
would be really good for.  OOC are there any "classic" examples of real life 
stuff Haskell does better than other languages?  Might give me some ideas.


Post a reply to this message

From: Invisible
Subject: Re: Try Haskell
Date: 15 Mar 2010 12:06:15
Message: <4b9e5af7$1@news.povray.org>
scott wrote:
>> I'm pretty sure if I tried to explain the rules of gravitation to a 
>> girl, I wouldn't _have_ a girlfriend for very long...
> 
> She wasn't interested in space before she met me, it's only when she saw 
> Saturn through the telescope that she thought it was really cool and 
> started to read a lot about it - she asks lots of questions.  But it's a 
> very fine line to tread, if I try to make things too simple I get the 
> "I'm not dumb - god who did you date before me" line, but go too far the 
> other way and you get "ok i don't understand, i give up, don't bother".

Hmm. Apparently you have a very cool girlfriend...

[I'm not going to continue this train of thought any further. I don't 
want to depress myself.]

>> Heh, oh well. I was expecting the reply to be "I can't think of 
>> anything that Haskell would be useful for". ;-)
> 
> Well that too :-)  I guess I just don't do much of the sort of stuff 
> Haskell would be really good for.  OOC are there any "classic" examples 
> of real life stuff Haskell does better than other languages?  Might give 
> me some ideas.

Parsers, compilers, interpretters, simulations, anything that does 
complex algorithmic processing. (I hear it's popular for things like 
financial modelling and IC design.)

Hypothetically Haskell _should_ be an excellent choice for things like 
cryptography and data compression, but in practise the performance tends 
to be suboptimal.

Anything where correctness is more important than performance or even 
possibly development cost. (I hear Haskell is sometimes used in 
safety-critical fields like avionics - although you don't actually *run* 
Haskell on embedded systems, you use it to generate the code that will 
be run, with strong guarantees about correctness of the generated code.)

Anything where parallel processing is useful. In theory this is the 
Killer Advantage of Haskell; normal Haskell programs consist of about 
98% pure code, which is inherantly thread-safe and hypothetically easy 
to parallelise. Again, in practise performance is a little too variable 
to claim that Haskell is the killer language for compute-bound problems.



As examples of some of the above:

- The Haskell Platform comes with Parsec, an impressive parsing library 
which I'm *sure* I must have documented here at least once before.

- GHC itself is written in 98% Haskell. (Stuff like the garbage 
collector and the I/O subsystem is written in C.) Think about it - what 
do compilers do? They parse stuff, and they transform code trees. These 
are both tasks which Haskell is excellent at.

- There's a small cottage industry for writing things like theorum 
provers, constraint solvers, neural networks, genetic algorithms and the 
like using Haskell. Writing these things typically isn't difficult; 
making it efficient is the tricky part. ;-)

- Hell, you may even remember that I wrote a small logic equation solver 
a while back. Remember? It could not only join to lists together, but 
also UNjoin them in every possible way. ;-) OK, not terribly useful, but 
quite satisfying to get it to work...

- I personally have also written ray tracers, fractal generators, 
compression and cryptography algorithms, and all sorts of other crazy 
stuff. If that's your thing, Haskell is a great way to write code 
quickly. (Not necessarily code that runs quickly, sadly.)


Post a reply to this message

From: scott
Subject: Re: Try Haskell
Date: 16 Mar 2010 03:43:38
Message: <4b9f36aa$1@news.povray.org>
> simulations,

I heard Haskell has OpenGL capability, how easy is that to get running - 
then we might be talking :-)


Post a reply to this message

From: Invisible
Subject: Re: Try OpenGL
Date: 16 Mar 2010 06:48:32
Message: <4b9f6200$1@news.povray.org>
scott wrote:

> I heard Haskell has OpenGL capability, how easy is that to get running - 
> then we might be talking :-)

Heh, OK, it's just taken me the entire morning to figure this out. 
(Documented? What do you mean documented? Why would it be documented??)

First: The Haskell Platform includes OpenGL out-of-the-box, so it should 
Just Work(tm).

Second: The documentation for OpenGL is missing, which made me spend 20 
minutes trying to figure out why it wasn't there. Querying the package 
list confirms that OpenGL actually *is* there, it's only the 
documentation that's missing. (Thanks, guys...)

Third: I compiled a simple OpenGL program, and it crashed with "cannot 
find glut32.dll". I don't know if that's because I don't have a 3D card 
on this machine or what. Anyway, it took a while to fix it! YMMV.

Start with this:

module Main where

import Graphics.Rendering.OpenGL
import Graphics.UI.GLUT

myPoints :: [(GLfloat,GLfloat,GLfloat)]
myPoints = map (\k -> (sin(2*pi*k/12),cos(2*pi*k/12),0.0)) [1..12]

main = do
   (progname, _) <- getArgsAndInitialize
   createWindow "Hello World"
   displayCallback $= display
   mainLoop

display = do
   clear [ColorBuffer]
   renderPrimitive Points $ mapM_ (\(x, y, z)->vertex$Vertex3 x y z) 
myPoints
   flush

Save that lot as Test.hs or something. Then execute

   ghc --make Test

That should generate Test.exe. Now run it.

If it whines about not finding glut32.dll, go here:

   http://www.transmissionzero.co.uk/software/freeglut-devel/

Download the "FreeGLUT MinGW" package, and unpack glut32.dll from it. 
(You can ignore all the other files; you only need the DLL.) Drop the 
DLL into your search path or just into the same folder as Test.exe, and 
then try and run it.

If it works, you should get a black window with some white dots.

Assuming all of that works, you now just need to learn the whole Haskell 
programming language, including how to do I/O, and learn the OpenGL 
binding, and then you can do stuff. ;-)

And now if you'll excuse me, I'm going to go file a bunch of tickets 
with the bugtracker. :-P


Post a reply to this message

From: Roman Reiner
Subject: Re: Try OpenGL
Date: 16 Mar 2010 07:05:01
Message: <web.4b9f64b5e7b75d5a1c2a3d200@news.povray.org>
Invisible <voi### [at] devnull> wrote:
> I compiled a simple OpenGL program, and it crashed with "cannot
> find glut32.dll". I don't know if that's because I don't have a 3D card
> on this machine or what. Anyway, it took a while to fix it! YMMV.

Yup, OpenGL doesn't ship with GLUT (OpenGL Utility Toolkit). You need to
download it separately.


Post a reply to this message

From: scott
Subject: Re: Try OpenGL
Date: 16 Mar 2010 07:29:05
Message: <4b9f6b81@news.povray.org>
> myPoints
>   flush
>
> Save that lot as Test.hs or something. Then execute
>
>   ghc --make Test

I get:

Test.hs:20:0: parse error (possibly incorrect indentation)

I guess something with the indentation is not correct at the end of the .hs 
file?  What does it need?


Post a reply to this message

From: Invisible
Subject: Re: Try OpenGL
Date: 16 Mar 2010 07:31:49
Message: <4b9f6c25$1@news.povray.org>
scott wrote:
>> myPoints
>>   flush
>>
>> Save that lot as Test.hs or something. Then execute
>>
>>   ghc --make Test
> 
> I get:
> 
> Test.hs:20:0: parse error (possibly incorrect indentation)
> 
> I guess something with the indentation is not correct at the end of the 
> .hs file?  What does it need?

The "myPoints" is supposed to be at the end of the previous line. 
Apparently it got wrapped...


Post a reply to this message

From: scott
Subject: Re: Try OpenGL
Date: 16 Mar 2010 07:44:26
Message: <4b9f6f1a$1@news.povray.org>
Cool it works!  (I had to rename freeglut.dll to glut32.dll)

Now to learn Haskell...


Post a reply to this message

From: Invisible
Subject: Re: Try OpenGL
Date: 16 Mar 2010 07:58:28
Message: <4b9f7264$1@news.povray.org>
scott wrote:
> Cool it works!  (I had to rename freeglut.dll to glut32.dll)

Oh, yeah, I forgot to mention that part. o_O

> Now to learn Haskell...

LOL! Um, yes. ;-)

You'd probably be best learning the pure part of Haskell first, since 
this is the primary objective of Haskell. The impure part of Haskell is 
just like any other language - but far, far more wordy. Thing is, OpenGL 
is all *about* the impure part, so...


Post a reply to this message

From: Invisible
Subject: Re: Try Haskell
Date: 19 Mar 2010 05:53:56
Message: <4ba349b4@news.povray.org>
scott wrote:

> You're also quite good a writing tutorials, you should definitely write 
> a book.  Haskell for Imperative Programmers.  :-)

If I write it, will you help review it?


Post a reply to this message

<<< Previous 10 Messages Goto Latest 10 Messages Next 2 Messages >>>

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.