Perl-Sensitive Sunglasses PerlMonks

### Re^5: 99 Problems in Perl6

by Ovid (Cardinal)
 on Dec 15, 2006 at 22:44 UTC ( #590141=note: print w/replies, xml ) Need Help??

in reply to Re^4: 99 Problems in Perl6
in thread 99 Problems in Perl6

Lest anyone think I'm a genius, I stole the Haskell code from here.

Cheers,
Ovid

New address of my CGI Course.

Replies are listed 'Best First'.
Re^6: 99 Problems in Perl6
by gaal (Parson) on Dec 15, 2006 at 22:54 UTC
The "alternative solution" posted there doesn't suffer from the monomorphism restriction*, and thus does less to propagate the myth that one has to be a genius to write code in Haskell. It also works correctly with empty input :-)

```compress []       = []
compress [a]      = [a]           -- singleton list
compress (x:y:xs) = (if x == y then [] else [x]) ++ compress (y:xs)
*Something that, for the casual programmer, is quite technical but uninteresting, has a scary name, and a not-that-friendly error message.
And indeed, you can do that in Perl too:
```multi compress () { () }
multi compress (\$a) { item \$a }
multi compress (\$x, \$y, *@xs) { \$x xx (\$x !=== \$y), compress(\$y, |@xs)
+ }

my @x = <a a a a b c c a a d e e e e>;
say perl compress |@x;
Didn't we end up using when for guards? The problem with multis for this I seem to remember was that it was hard to spec their order if they're defined in separate compilation units.

Create A New User
Node Status?
node history
Node Type: note [id://590141]
help
Chatterbox?
 [Corion]: choroboa: A good choice! ;) [Corion]: I still somewhat wonder if it were worthwhile to replace init / systemd by make with a simple? Makefile listing the dependencies ... [Discipulus]: i have a different opinion: automation is always worth: first i can use Perl (and this is good), then later you can reuse parts to automate others tasks. My \$boss everytime say:'how much time you spend doing this?' So generally i present a perl solution [Corion]: Discipulus: Yes, but the chart gives some limits on whether it's really worth spending time for saving your time. If you gain enjoyment, automating is still great, but it doesn't save time ;)

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2017-07-27 09:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
I came, I saw, I ...

Results (408 votes). Check out past polls.