POV-Ray : Newsgroups : povray.off-topic : I found this interesting : Re: [Caution: long monad ramble] Server Time
1 Oct 2024 15:20:59 EDT (-0400)
  Re: [Caution: long monad ramble]  
From: Darren New
Date: 11 Apr 2008 21:30:22
Message: <480010ae$1@news.povray.org>
Orchid XP v8 wrote:
>> figure out how to make while() into a function that takes two lambdas. 
> 
> There's takeWhile, dropWhile and span which chop up segments of lists. 
> There's "unfoldr" which builds lists. There's "until", which repeats a 
> computation until a condition holds, and returns the final result. And 
> so on...

Erlang has all that stuff. They aren't "while" loops, tho, they're "for" 
loops. No way to stop foldr() early, no way to have it get its stuff by 
(say) reading lines from a file instead of a list, etc.

No way to say "while you haven't gotten to a directory entry that starts 
with the letter 'T' in /tmp, ...."

> Interestingly, Haskell possesses a "guard" function:
> 
>   guard (x*y == k)
>   return (x,y)
> 
> If the condition fails, guard aborts the rest. Otherwise it continues. 

That's what the "when" stuff above is - guards.

And a case statement and an if statement both use guards, as does the 
message receiving.  The languages do seem very close to each other in 
capability, from my naive view.

> I should perhaps also mention "return" and "fail" somewhere. All monads 
> have a "return" method that inserts a single element into the monad:
> 
>   return 5 >>= print

Odd name. Not sure what that means. :-)

> is the same as just "print 5". The "fail" method takes a text message 
> and aborts the computation. For Maybe or lists, the message is ignored, 
> but for the IO monad it throws an exception. 

And Erlang crashes the process out, which sends "I crashed" messages to 
anyone "linked" to that process, which in turn either crashes them out 
or just queues a message saying they crashed.

> Theoretically, you might have something like
> 
>   data IO x =
>     CMD_GET_CHAR Handle |
>     CMD_PUT_CHAR Handle |
>     CMD_TEST_EOF Handle |
>     ...
>     CMD_GET_CLOCK_TIME |
>     ...

Hrm. OK.

>> Wow. You have your own newsgroup. :-)
> Where *have* you been dear boy? ;-)

Well, I remember it being created as a joke, but I never subscribed. :-)

-- 
   Darren New / San Diego, CA, USA (PST)
     "That's pretty. Where's that?"
          "It's the Age of Channelwood."
     "We should go there on vacation some time."


Post a reply to this message

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