POV-Ray : Newsgroups : povray.off-topic : Try Haskell : Re: Try Haskell Server Time
4 Sep 2024 17:22:15 EDT (-0400)
  Re: Try Haskell  
From: scott
Date: 4 Mar 2010 05:47:32
Message: <4b8f8fc4@news.povray.org>
>> BTW what would happen if I typed "choose 3 (-5)" instead?
>
> Well, it would execute
>
>   (factorial 3) / (factorial (-5) * factorial (3 + 5))
>
> Given the above definition of factorial,
>
>   factorial (-5) = product [1..-5] = product [] = 1
>
> Which I'm guessing means that choose gives the wrong answer.

So what's the preferred way to cope with runtime "errors" like that? (I 
don't know if there is a technical term for such kind of errors that don't 
actually make an error, if you know what I mean).  I suspect in a lot of 
case some very low nested function detects an error, and needs to signify 
this to a much higher level calling function (eg a "ParseFile" or 
"ParseLine" function or something).

> So Suit and Number are enumerations, and Card is a record with two fields. 
> The record syntax is probably the most perplexing part. I'm using 
> positional fields - which is common when there are very few fields - but 
> you can also use named fields:
>
>   data Card = Card {suit :: Suit, numer :: Numer}

OK, so I could also do something like:

data myRecord = myRecord {age :: Int, height :: Double, weight :: Double}

> Are all the cards the same suit?
>   length (group (map suit cards)) == 1
> (This could be inefficient if "cards" is huge, but for a hand of 5 or 7 
> cards, it should be fine.)
>
> First, you extract a list of suits.

So in my example, if I had a list of myRecords, then "age MyList" would 
return a list of ages?

> Then you group this list into a list of sublists, such that each sublist 
> contains only identical suits.

What does the "map" do?  Clearly I need to download the proper 
interpretter/compiler to answer these questions myself with a bit of playing 
around :-)

OK so after Googling Haskell, implementations, GHC, go to the GHC page, 
latest release, "STOP!" they recommend I get the Haskell Platorm instead, oh 
goody a .exe installer link :-)  I'll let you know in 54 MB time how I get 
on...

> LOL! OK, well if you put it that way...

Thing is it's very rare that I find myself wanting to write something that 
*I* think would be easier/faster with a language like Haskell.  But as I 
don't really know much about the language, I'm not a very good judge.

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


Post a reply to this message

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