Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

vroom vroom

Name: Anonymous 2012-11-20 23:17

post code in this thread and it will be rewritten in c.

Name: Anonymous 2012-11-20 23:23

Name: Anonymous 2012-11-20 23:24

>>2

oh you

Name: Anonymous 2012-11-20 23:39

import Control.Applicative

add :: (Applicative f, Num a) => f a -> f a -> f a
add = (<*>).((+)<$>)

Name: Anonymous 2012-11-20 23:40

>>4
FUCK!

import Control.Applicative

add :: (Applicative f, Num a) => f a -> f a -> f a
add = (<*>).((+)<$>)

Name: query received 2012-11-21 0:20

>>5
I will try to finish within 24 hours. Stay tuned.

Name: Anonymous 2012-11-21 1:37

>>6
Here are some test cases for you:

Haskell:
> add (pure 1) (pure 2)
3


C:
add(1, 2) == 3

Haskell:
> add (Just 1) Nothing
Nothing


C:
int x = 1;

add(&x, NULL) == NULL


Haskell:
> add [1,2,3] [10,20,30]
[11,21,31,12,22,32,13,23,33]


C:
int *xs = { 1, 2, 3 }, *ys = { 10, 20, 30 };

add(xs, ys) == { 11, 21, 31, 12, 22, 32, 13, 23, 33 }


Haskell:
> let m = putStr "? " >> readLn in add m m
? 1
? 2
3


C:
int f() {
  int x;

  printf("? ");
  scanf("%d", &x);

  return x;
}

add(&f, &f) == 3 /* if the user types in 1 and 2 */


Haskell:
> add (+1) (*2) 3
10


C:
int f(int x) {
  return x + 1;
}

int g(int x) {
  return x * 2;
}

int (*result)(int);

result = add(&f, &g);

result(3) == 10


My C's a little rusty. Some of those examples might be a little off, but hopefully the meaning is obvious.

Name: Anonymous 2012-11-22 0:40


int add1(int a, int b) {
  return a + b;
}

int add2(int a, int a_ok, int b, int b_ok, int* c) {
  if(a_ok && b_ok) {
    *c = a + b;
    return 1;
  }

  return 0;
}

void add3(int* a, int a_len, int* b, int b_len, int* c) {
  int i1, i2, i3;
  i3 = 0;
  for(i1 = 0; i1 < b_len; i1++) {
    for(i2 = 0; i2 < a_len; i2++, i3++) {
      c[i3] = a[i2] + b[i1];
    }
  }
}

int add4(int (*f)(int), int (*g)(int), int x) {
  return f(x) + g(x);
}


ok. Next!

Name: Anonymous 2012-11-22 0:41

I forgot to not sage

Don't change these.
Name: Email:
Entire Thread Thread List