juan_gandhi: (Default)
Turned out all the delays were caused by two things:
- reading the files in parallel, as opposed to sequential (don't ask, will investigate)
- parallel output to stdout, instead of linearising the output. That was obviously my mistake, have to group the data, not mix them.

Now it's still 3 times faster than FP version. Got a suspicion that in JVM method dispatch is much heavier than plain if/else. It should be. But it's the staple of FP, never use booleans or ifs, but dispatch by the type. So, well... have to investigate.
juan_gandhi: (Default)
 https://vpatryshev.wordpress.com/2017/01/20/three-popular-fp-myths-3/

More Haskell bashing.

"Haskell is so good that if a functor does not have a free monad, it cannot be written in Haskell". Which is funny. Something like Haskell version of Church thesis.
juan_gandhi: (Default)
As promised (to myself), started writing the "three myphs of FP".

https://vpatryshev.wordpress.com/2017/01/07/three-popular-fp-myths/
 - part 1, "not every monad is strong" 
juan_gandhi: (VP)
https://arxiv.org/pdf/1611.09475.pdf

Domain-Specific Languages of Mathematics: Presenting
Mathematical Analysis Using Functional Programming
juan_gandhi: (VP)
/**
 * A marker interface for classes that have no data inside
 * Meaning, two instances are equal if they have the same class
 */
public interface JustCode extends Serializable {
}
...
public interface Function<X, Y> extends JustCode {
  Y apply(X x);
}
...
public interface Function2<X, Y, Z> extends JustCode {
  Z apply(X x, Y y);
}
...
  
  public int hashCode(JustCode x) {
    return x == null ? 0 : x.getClass().hashCode();
  }

  public boolean equal(JustCode x, JustCode y) {
    return x == null ? y == null : y != null && x.getClass() == y.getClass();
  }



No shit, just discovered this kind of data.
You've probably noticed that I kind of prefer S to OOP. :)
juan_gandhi: (VP)
  // test how file can be unfolded into multiple columns
  public void testUnfoldingColumn() throws IOException {
    // Here's the file
    File file = getFile("smalldata/chicago/chicagoAllWeather.csv");

    // Get all its lines
    final List<String> lines = Files.readLines(file, Charset.defaultCharset());

    // Store it in H2O, with typed column as a wrapper (core H2O storage is a type-unaware Vec class)
    Column<String> source = willDrop(Strings.newColumn(lines));

    // Produce another (virtual) column that stores a list of strings as a row value
    Column<List<String>> split = new UnfoldingColumn<>(Functions.splitBy(","), source, 10);

    // now check that we have the right data
    for (int i = 0; i < lines.size(); i++) {
      // Since we specified width (10), the rest of the list is filled with nulls; have to ignore them.
      // It's important to have the same width for the whole frame..
      String actual = StringUtils.join(" ", Predicate.NOT_NULL.filter(split.apply(i)));
      // So, have we lost any data?
      assertEquals(lines.get(i).replaceAll("\\,", " ").trim(), actual);
    }
  }
juan_gandhi: (VP)
Вот какую хуйню приходится пока писать на работе:

  public static  Iterable<Y> map(Iterable<X> xs, Function<X,Y> f) {
    List<Y> ys = new LinkedList<Y>();
    for (X x : xs) ys.add(f.apply(x));
    
    return ys;
  }
  
  
  interface Option<T> extends Iterable<T> {
    T get();
  }
// etc

puzzle

Oct. 4th, 2016 08:17 am
juan_gandhi: (VP)
For endomorphisms, eval: X × XX → X can be rewritten as X(1+X) → X, or, in code, as (Option[X] → X) → X - almost like Y in ML.

Just can't figure out the consequences out of this simple representation.
juan_gandhi: (VP)
  def ×[A,B,C,D](f:A=>C)(g:B=>D): (A,B) => (C,D) = (a,b) => (f(a), g(b))


Big deal, right?

got it

May. 4th, 2016 04:54 am
juan_gandhi: (VP)
Stroustrup said he does not know how come functional programming failed.

I don't know if it failed, but I see now how come it's so hard for the people.

Programming people, en masse, are clueless regarding what a function is. Seriously.
juan_gandhi: (VP)
Every time you write
val myName = props.get("Name") orElse ""
you are introducing an algebra over Option monad.
Even if you have no clue what an algebra or a monad is.

Same goes for catching exceptions and returning a "default value". Now you have a category of algebras over the exception monad.

This category is called Eilenberg-Moore category for the monad. There's a couple of adjunctions of course.

Kleisli also provides a couple of adjunctions.

All possible adjunctions make a category, where Kleisli is an initial object and Eilenberg-Moore is a terminal object.

Nlab says that Kleisli can actually be embedded into Eilenberg-Moore.

Meaning, guys, you don't need to invent "default values"; just use Option[T]. Whatever. Probably hard to explain to people that are thinking in terms of saving computer memory on string instantiation.
juan_gandhi: (VP)
Could not figure out Arrows.

Are they profunctors with a) monadic structure, and b) something like monadic strength?

And why are they so good?

good stuff

Aug. 15th, 2015 04:58 pm
juan_gandhi: (VP)
A lot of good stuff at Scala by the Bay; this one is pretty important:

Michael Pilquist, Scodec.

https://speakerdeck.com/mpilquist/a-tour-of-functional-structures-via-scodec-and-simulacrum

Profile

juan_gandhi: (Default)
juan_gandhi

August 2017

S M T W T F S
   1 23 4 5
6 7 8 9 10 11 12
13 14 15 16 1718 19
20 21 2223242526
2728293031  

Syndicate

RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 23rd, 2017 06:20 am
Powered by Dreamwidth Studios