These are chat archives for got-lambda/expression

6th
Dec 2017
Jean-Louis Giordano
@Jell
Dec 06 2017 06:15 UTC
so I tried to compile Day 5 in Idris and after 7h and running out of swap space it died... Works on the short example!
(I mean it died during compilation, never got to the running bit)
Magnus Therning
@magthe
Dec 06 2017 08:43 UTC
@Jell Does that mean you've tied the types to the indata?
Jean-Louis Giordano
@Jell
Dec 06 2017 08:43 UTC
yeah using type providers
indata is static in my solution
Magnus Therning
@magthe
Dec 06 2017 08:45 UTC
Cool!
Or well, maybe fascinating is a better word :)
yeah it's interesting, Idris is for now the only one that segfaulted at runtime and failed to terminate compilation
(while solving those puzzles)
PureScript runtime died because strictness and me failing at using lazy collections in it
segfault was due to type providers, so I'm blaming C for that
Magnus Therning
@magthe
Dec 06 2017 09:05 UTC
I think about 80% of all segfaults ever can be blamed on C :laughing:
Fredrik Dyrkell
@fredyr
Dec 06 2017 10:22 UTC
100% can be blamed on computerz!!
(:
Erik Svedäng
@eriksvedang
Dec 06 2017 10:58 UTC
word
jolod
@jolod
Dec 06 2017 11:39 UTC
@Jell What was the problem with laziness in PS?
I don't use unfolds everyday, but the other day I wrote the global RE match function using lazy unfold where lastIndex was the state. Really nice.
Magnus Therning
@magthe
Dec 06 2017 11:44 UTC
When unfold can be used it often creates really nice solutions.
Jean-Louis Giordano
@Jell
Dec 06 2017 13:22 UTC
@jolod I could not figure out how to use Lazy lists, I used head $ cycle $ fromFoldable [1,2,3] and that crashes
do you have some tips that I'm missing?
jolod
@jolod
Dec 06 2017 13:38 UTC
@Jell Why do you cycle and then take the head? Is this just a condensed example?
Jean-Louis Giordano
@Jell
Dec 06 2017 14:39 UTC
yes it's a narrowed down example of the issue
I haven't figured out how to consume an infinite list really?
any tips on that?
jolod
@jolod
Dec 06 2017 14:41 UTC
@Jell How much can you consume before it goes boom?
Jean-Louis Giordano
@Jell
Dec 06 2017 14:42 UTC
≈1000 when I use index
I think a reference to the head is kept somewhere
but can't figure out where / how
hum
trying this at the REPL now it works
wth
jolod
@jolod
Dec 06 2017 14:45 UTC
Just to be clear. You are using LazyList.cycle, not List.cycle? (And are you sure?)
Jean-Louis Giordano
@Jell
Dec 06 2017 14:45 UTC
yeah now I'm not so sure, because when I ran this at the REPL it worked, when I ran it yesterday at the REPL it did not, I might have failed my imports
jolod
@jolod
Dec 06 2017 14:45 UTC
fromFoldable can produce either a List or a lazy List.
Jean-Louis Giordano
@Jell
Dec 06 2017 14:46 UTC
damn, that must have been it then
ok I'll try again! :heart:
jolod
@jolod
Dec 06 2017 14:46 UTC
Or, there's many implementations of fromFoldable in different places.
I always qualify things like that, so I know which one I'm using.
But no.
Jean-Louis Giordano
@Jell
Dec 06 2017 14:47 UTC
I assumed cycle only accepted lazy lists
jolod
@jolod
Dec 06 2017 14:47 UTC
cycle is only in lazy list I think. So it must be lazy list for fromFoldable as well.
Yeah.
Jean-Louis Giordano
@Jell
Dec 06 2017 14:47 UTC
ah.
jolod
@jolod
Dec 06 2017 14:47 UTC
@Jell Have you looked at the generated JS?
Jean-Louis Giordano
@Jell
Dec 06 2017 14:47 UTC
hum... didn't think of that
thanks for all the good pointers :p
jolod
@jolod
Dec 06 2017 14:48 UTC
Try it. Sometimes it's surprisingly helpful.
Jean-Louis Giordano
@Jell
Dec 06 2017 14:48 UTC
:thumbsup:
jolod
@jolod
Dec 06 2017 14:48 UTC
Sometimes, when you use too many type classes, it's not helpful at all. :-)
Jean-Louis Giordano
@Jell
Dec 06 2017 14:48 UTC
:D
ah wait! sorry wrong example
this crashes after 10000 iterations:
index (iterate ((+) 1) 1) 10000
with Maximum call stack size exceeded
jolod
@jolod
Dec 06 2017 14:52 UTC
Which iterate is that?
Jean-Louis Giordano
@Jell
Dec 06 2017 14:52 UTC
I did
import Prelude
import Data.List.Lazy
(at the REPL)
I don't think there's a version of iterate that's not lazy?
ok both index & iterate are coming from Data.List.Lazy
can I get the JS from the REPL?
jolod
@jolod
Dec 06 2017 14:54 UTC
Dunno.
I'm not much of a repl guy, and when I just want to try out non-project specific things I sometimes do it in try.purescript.org.
Jean-Louis Giordano
@Jell
Dec 06 2017 14:57 UTC
ah good idea
jolod
@jolod
Dec 06 2017 14:57 UTC
You get re-eval, and generated JS.
Jean-Louis Giordano
@Jell
Dec 06 2017 15:01 UTC
killed try.purescript.org with that example
the generated JS:
"use strict";
var Control_Monad_Eff = require("../Control.Monad.Eff");
var Data_Function = require("../Data.Function");
var Data_List_Lazy = require("../Data.List.Lazy");
var Data_Maybe = require("../Data.Maybe");
var Data_Semiring = require("../Data.Semiring");
var Data_Show = require("../Data.Show");
var Prelude = require("../Prelude");
var TryPureScript = require("../TryPureScript");
var x = Data_List_Lazy.index(Data_List_Lazy.iterate(Data_Semiring.add(Data_Semiring.semiringInt)(1))(1))(10000);
var main = TryPureScript.render(TryPureScript.h1(TryPureScript.text(Data_Show.show(Data_Maybe.showMaybe(Data_Show.showInt))(x))));
module.exports = {
    main: main, 
    x: x
};
jolod
@jolod
Dec 06 2017 15:04 UTC
Yeah, for this you need to look into the libraries. But iterate uses fix, and I've never used fix myself but it seems clever. :-)
It's obviously not an issue with your code.
jolod
@jolod
Dec 06 2017 15:10 UTC
Btw, how would you want drop n to work for negative n?
And how does Haskell work?
Jean-Louis Giordano
@Jell
Dec 06 2017 15:10 UTC
idris solves it with using Nat obviously
only total solution would be do nothing?
jolod
@jolod
Dec 06 2017 15:12 UTC
Obviously. (I guess 0 is a natural number then?)
Jean-Louis Giordano
@Jell
Dec 06 2017 15:12 UTC
yeah
jolod
@jolod
Dec 06 2017 15:12 UTC
(Debatable definition of natural number. ;-))
Anyway, I looked at the PS code and saw that drop with negative arguments drops everything. So you get Nil back.
Jean-Louis Giordano
@Jell
Dec 06 2017 15:13 UTC
hum... that's... interesting?
so the garbage in -> garbage out approach?
jolod
@jolod
Dec 06 2017 15:14 UTC
I think it would want n <= m => length (drop n xs) >= length (drop m xs).
I.e. drop nothing if negative.
s/think it would/think I would/.
Jean-Louis Giordano
@Jell
Dec 06 2017 15:16 UTC
yes that's what I'd expect as well
Magnus Therning
@magthe
Dec 06 2017 15:17 UTC
fix is cool, it's another one of my ideas for presentations... together with Fix (all in Haskell though)
jolod
@jolod
Dec 06 2017 15:17 UTC
@magthe In the mean time, do you have any good reading material?
Magnus Therning
@magthe
Dec 06 2017 15:18 UTC
@jolod I'll see if I saved anything
otherwise you can just start implementing every basic recursive function you know using fix for the recursive step :)
jolod
@jolod
Dec 06 2017 15:19 UTC
I can't remember the last time I wrote a recursive function in a FP language.
Yes, actually. It was when I implemented Dijkstra.
jolod
@jolod
Dec 06 2017 16:11 UTC
@Jell Could the problem be that the list get's wrapped too many times in defer?
So when you then force it, you force recursively a lot.
fix uses map and map wraps the call in a defer-force.
jolod
@jolod
Dec 06 2017 16:16 UTC
I don't know ...
Jean-Louis Giordano
@Jell
Dec 06 2017 16:54 UTC
I should try looking at the stacktrace