github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

osfameron / acme--monads

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 5
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Monads in pure Perl, using Devel::Declare — Read more

  cancel

http://greenokapi.net/blog/tag/monads/

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Added hacks to add the parsed prototype to the mdo block. 
osfameron (author)
Sat Apr 25 15:06:33 -0700 2009
commit  d8926834a964c52939f1c54237af412771028c25
tree    e49abd1098ee66e04f4e8464cb7948b99ed4a5c3
parent  42d6a353a284244a9f009199bce17644822a1c77
acme--monads / t / 04_curry.t t/04_curry.t
100755 49 lines (38 sloc) 1.219 kb
edit raw blame history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/perl
use strict; use warnings;
 
use Data::Dumper;
 
use Test::More tests => 9;
use Test::Exception;
 
use Monad;
use Monad::Curry;
 
# This API for declaring number of arguments is sucky!
# ... and also doesn't work
my $add = mdo (2) {
    mbind $x = Curry shift;
    mbind $y = Curry shift;
    return $x+$y; # not munit... which makes this strictly speaking not monadic
    };
 
my $triangle = mdo (3) {
    mbind $x = Curry shift;
    mbind $y = Curry shift;
    mbind $z = Curry shift;
    return $x+$y+$z;
    };
 
ADD: {
    isa_ok($add, 'CODE');
 
    is ($add->(1)->(2), 3, 'Sorta-monadic curried addition');
    is ($add->(1, 2), 3, '2 args at once');
    throws_ok { $add->(1,2,3) } qr/Expected 2 args but got 3/;
}
 
# We alternate here to test that the hacks to keep Monad::Proto are cleanish
TRIANGLE: {
    is ($triangle->(1,2,3), 6, 'Triangle');
    is ($triangle->(1,2)->(3), 6, 'Triangle');
    is ($triangle->(1)->(2,3), 6, 'Triangle');
    throws_ok { $triangle->(1,2)->(3,4) } qr/Expected 1 args but got 2/;
}
 
ADD2: {
    # back to make sure local $Curry::Args thing is sane
    my $add2 = $add->(2);
    is_deeply( [map $add2->($_), (1..3)], [3..5], 'partially applied add2 worked' );
}
 
 
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server