<RobertFischer>
kig: Phase 1 is using too many semicolons. Phase 2 is exposing underlying modules (recursive modules). Phase 3 is rewriting stdlib. :)
ecc_ has joined #ocaml
ecc_ has quit [Client Quit]
Naked is now known as Hadaka
Snrrrub has joined #ocaml
munga_ has quit ["Ex-Chat"]
authentic has quit [Read error: 104 (Connection reset by peer)]
<bluestorm>
kig:
<bluestorm>
| [] -> failwith "foldr1"
<bluestorm>
you should use invalid_arg
<bluestorm>
(imho, fold_right : ('a -> 'b -> 'b) -> ('a t -> 'b -> 'b) is the good parameter order)
Kopophex has joined #ocaml
hcarty has quit ["leaving"]
LordMetroid has joined #ocaml
redocdam has joined #ocaml
Axioplase_ is now known as Axioplase
arquebus has joined #ocaml
CrawfordComeaux has joined #ocaml
jeremiah has quit []
<CrawfordComeaux>
I want to have a list that contains ever-changing preconditions required for a function. Would the best way to implement this be to simply store the conditions as a string that build a parser for?
<bluestorm>
hm
RobertFischer has left #ocaml []
<bluestorm>
CrawfordComeaux: can you not represent them a closures ?
<bluestorm>
if your function is 'a -> 'b , then a ('a -> bool) list could be enough
<bluestorm>
(that suppose uncurrified functions)
<CrawfordComeaux>
ok
<CrawfordComeaux>
apparently I need rest...I should've known how to do that
* rwmjones
wants jacques garrigue to answer the question about extending immediate objects ...
<kig>
bluestorm: good point on invalid_arg, thanks. imho, the list-last arg order of foldr is more in line with the rest of the list funcs (plus i started it as a port of haskell's prelude, which uses the list-last arg order)
<bluestorm>
rwmjones: weren't you impressed by the ugly Obj.magic solution ?
<rwmjones>
heh ... no because basically it's not type safe :-(
<rwmjones>
the point is to have a typesafe solution, and casting the return value is not that
hcarty has joined #ocaml
<rwmjones>
bluestorm, your answer to the 'what is the current function' question is the one I thought about too, but surely the same information is available, at least in bytecode, using whatever the stacktrace mechanism uses
<bluestorm>
rwmjones: you're right, but i don't think this code is easy to access from the outside
<bluestorm>
whereas camlp4 is quite comfortable in that aspect
mishok13 has quit [Read error: 104 (Connection reset by peer)]
<tar_>
I have a Map from int * int that I want to initialize with the coordinates of a 9x9 grid ((0, 0), (0, 1), ...).
<tar_>
I'd like to do it concisely, but the best I've gotten so far is http://pastie.org/233102 (making functions init_square, init_col, and init_grid)
arquebus has left #ocaml []
<rwmjones>
uh oh, university exercise?
<bluestorm>
sudoku ?
<bluestorm>
tar_: i suggest a reference and two for loops
<tar_>
bluestorm got it <--
<tar_>
Oh, that would work
<Jeff_123>
ewww loops
<bluestorm>
:]
<bluestorm>
the other solution would be to declare a seq : int -> int -> int list primitive and use it for good
authentic has joined #ocaml
<tar_>
bluestorm: Could you explain that a little more?
<bluestorm>
tar_:
<bluestorm>
let seq = Array.to_list (Array.init 9 (fun x -> x)) in List.fold_right (fun x -> List.fold_right (fun y -> M.add (x, y) seq) seq) seq M.empty
<bluestorm>
my idea was to have a seq 1 9 = [1; 2; ..; 8; 9]
<bluestorm>
but actually you only use [0...8] so a value is fine
<bluestorm>
tar_: actually, if you want your sudoku to be efficient, i would suggest you use an int list array array instead
<bluestorm>
tar_: your init_grid () function (why "()" btw ?) is quite exactly a fold_left
<bluestorm>
as your init_col actually
<tar_>
Hrm.
<bluestorm>
if you're not already familiar with fold_[left/right], you should play with them a little, it's quite cool and good exercise
<tar_>
It's still so new I hadn't thought of them. Actually, I was about to rewrite those to take a function and then it really would have been fold_left.
<tar_>
The () was because my editor's syntax coloring seemed to fail without any arguments listed. :)
<kig>
it's still far from the haskell [(x, y) | x <- [0..8], y <- [0..8]], though :/
TypedLambda has joined #ocaml
* tar_
switches to Haskell
<bluestorm>
tar_: no need
<tar_>
I thought I'd seen a sole () argument in the standard library somewhere. Is that for when refs are involved?
<bluestorm>
you add a sole () argument when you don't want your declaration to be an immediate value
<tar_>
I may also be remembering wrong..
<bluestorm>
for example
<bluestorm>
let foo = print_endline "Hello World !"
<bluestorm>
will be executed once
<tar_>
Ah
<bluestorm>
le foo () = print_endline "Hello World"
<bluestorm>
will be executed on callsite
<tar_>
Oh yeah, I think it was print_newline
^authentic has joined #ocaml
<bluestorm>
kig:
<bluestorm>
$ camlp4o Camlp4Parsers/Camlp4ListComprehension.cmo -str '[(x, y) | x <- 0--8; y <- 0--8]'
<bluestorm>
List.concat
<bluestorm>
(List.map (fun x -> List.map (fun y -> (x, y)) (0 -- 8)) (0 -- 8))
<kig>
nice
<tar_>
hey..
<bluestorm>
tar_: regarding "your editor coloring", iirc tuareg won't highlight the immediate values (or thought so) and the functions wich explicit parameters the same way
<bluestorm>
but that should not influence the way you code
<kig>
and my head went weird from writing too many unfolding examples. two maps better
<tar_>
Where did you get --?
<bluestorm>
tar_: he declared it himself
mfp_ is now known as mfp
<bluestorm>
let (--) a b = Array.to_list (Array.init (b - a + 1) ((+) a))
<bluestorm>
or let rec (--) a b = if a < b then a :: (a + 1) -- b else if a > b then a :: (a - 1) -- b else [b] if you want both directions