<gasche>
I implemented levensthein-based typo detection in the OCaml type-checker, and I just called levenstein on each identifier in the environment (works well enough for not needing anything more clever so far)
<whitequark>
it's for an utility called filecheck which I stole from LLVM... it's best demonstrated by an example
<whitequark>
it's a nice library, but as you've said, a little overkill here :)
librarian has joined #ocaml
testcocoon has quit [Ping timeout: 264 seconds]
osho0000 has joined #ocaml
<osho0000>
hello, can i find help here for exam problems?
<osho0000>
how can I check if in a bin tree the value of a parent is bigger that the values of childer?
<kerneis>
osho0000: what kind of binary tree? any one, or a specific (balanced? binary search?) tree?
mcclurmc1 is now known as mcclurmc
<kerneis>
oh, and do you mean of that the parent is larger than one child, both children, every descendant?
<kerneis>
it would help if you gave a small code example with your datatype
<osho0000>
both children..
<osho0000>
type tree = Nill | Node of tree * int * tree;;
testcocoon has joined #ocaml
<osho0000>
normal tree :)
<kerneis>
well, you can use pattern matching:
<osho0000>
i can show what i try..
<kerneis>
sure
<kerneis>
(the type of tree is important because you might have values at you leaves, for instance)
<kerneis>
something like this should get you started: "match t with Node(Node(_, child1, _), parent, Node(_, child2, _) -> if ... then ... else ... | _ -> ..."
<osho0000>
i used a pattern matching tree -> bool, but i dont know how to compare a node od the tree with it subtree..
<kerneis>
you can nest patterns in pattern-matching
<kerneis>
then in the if ..., use the variables child1, child2 and parent
<kerneis>
(poorly named, obviously, sorry)
<osho0000>
hm.. i try this but from here don't know how to go on
<osho0000>
let rec check tree = match tree with Nill -> true |Node(Nill,n,Nill) -> true |Node(c1,n,c2) -> check l && check d |Node(l,v,d) -> false;;
_andre has joined #ocaml
<kerneis>
well, you first two patterns look good
<kerneis>
the last two are redundant (so the last one will never match)
<osho0000>
the but in the third i really don't know..
<kerneis>
you need to replace your third pattern by the one I gave you
<kerneis>
that is to say, you need to pattern-match on "a node the children of which are also nodes"
<kerneis>
not "a node the children of which could be anything"
<osho0000>
ok I will try now
<osho0000>
thanks
<osho0000>
:)
<kerneis>
(and then, ocaml will warn you that your pattern matching is not exhaustive, and give you an example, but you can fix it later)
<kerneis>
(so focus on that case right now)
<osho0000>
ok :)
Neros has joined #ocaml
introom has joined #ocaml
ccasin has quit [Ping timeout: 245 seconds]
<osho0000>
kerneis ok i repair the code, but it returns me a Syntax error, dont konw where..
<osho0000>
let rec check tree = match tree with Nill -> true |Node(Nill,n,Nill) -> true |Node(Node(_,c1,_),p,Node(_,c2,_)) -> if (p>c1 && p>c2) then (check Node(_,c1,_) && check Node(_,c2,_)) |Node(l,v,d) -> false;;
<Kakadu>
osho0000: probably you need to add then ....
<Kakadu>
to your If statement
<rixed>
Kakadu: you mean "else" not "then" ?
<Kakadu>
rixed: okay, you got me
<rixed>
that wouldn't be a syntax error but a type error
<Kakadu>
rixed: I agree but it's hard to me to read code written in a single line...
<Kakadu>
Btw,
<Kakadu>
I have created demo app of my slow parsers
<kerneis>
osho0000: write check (Node(...)) instead of check Node(...)
<kerneis>
the later is parsed as (check) (Node) (...)
<kerneis>
hence the "Node is applied to zero arguments" error
<kerneis>
then, your function is accepted
<kerneis>
btw, you can also use "as" in your pattern-matching:
<kerneis>
|Node((Node(_,c1,_) as left),p,(Node(_,c2,_) as right)) when (p>c1 && p>c2) -> check left && check right
<osho0000>
yes 0 errors :)
<osho0000>
thanks
<kerneis>
that way, you can introduce a variable and name only the parts you need
<osho0000>
why if I write _ instead of a b c and d in my code it give me a error?
<osho0000>
interestig!
<kerneis>
on the left or on the right of the ->?
<osho0000>
both
<kerneis>
on the left, it shouldn't
<kerneis>
(but then the variable will not be defined on the right)
yezariaely has joined #ocaml
<kerneis>
on the right, _ does not make sense; _ means "bind this part to a variable, but in fact I don't care about this variable, so you can forget its name right now"
<yezariaely>
someone here using/developing ocamlmerlin? I like the tool but it sometimes gives me a two abstract type :/
<yezariaely>
I don't really understand why.
<kerneis>
gasche is the one who wrote the announce
<yezariaely>
e.g. let sigma = ref @@ Sigma.of_enum @@ BatList.enum [("a","q_a");("b","q_b")] in, then TypeOf for sigma return 'a
<asmanur_>
it often means your code is not valid for merlin
<yezariaely>
asmanur_: what are the specs for "valid"
<asmanur_>
almost "valid for ocaml"
<yezariaely>
well, it compiles correctly.
<yezariaely>
and in the .annot file, the correct type is given.
<asmanur_>
yezariaely: does merlin know about Sigma ?
<asmanur_>
and BatList
<yezariaely>
I don't know. How can I ask it? or tell it?
<gasche>
Kakadu: my remark on Qt was not meant to downplay your work on Qt
<asmanur_>
yezariaely: to use merlin properly, you should write a .merlin for your projects, telling what libraries you are using
<asmanur_>
eg. for your case your .merlin would be something like
<asmanur_>
PKG batteries
<asmanur_>
PKG <findlib package containing sigma>
<gasche>
(in fact I happen to have worked on my own ocaml-qt binding in the past, that was never released because it never got good enough to be useful, and I know it's very hard)
<yezariaely>
ah I see. Is there any doc about that? I didn't find any?! (and :help merlin.txt, doesn't work, though :helpgrep merlin.txt works)
<gasche>
Kakadu: it's just that I personally don't like GUI programming, and am bad at binding issues, so I meant that I won't personally get very much involved in your Qt work
<def-lkb>
(make sure you rebuilt tags, :Helptags)
<yezariaely>
def-lkb: now it works, I had to rebuild helptags.
<yezariaely>
yeah sorry ;) forgot to do that.
<gasche>
while a combinators + parsing + ocaml performance discussion is in my comfort zone
<yezariaely>
asmanur_: I read the readme, though it is not really helpful.
<yezariaely>
It does not even tell about <leader>t or such things
<gasche>
yezariaely: merlin devs suck at writing documentation, feel free to send them a pull request for some of it, or at least point out what's missing on their issue tracker
<yezariaely>
hehe ;-) Problem is that I do not understand how it works, so I can't write docs ;-)
<gasche>
(this morning's obvious missing content was "an announce for the last release", so I did my share0
<gasche>
yezariaely: that's the best time to write a doc
<gasche>
list the question you have as a beginner
<gasche>
send it in this form, or write down the answers where you can
<gasche>
and voilà, you've got something better than what already exists
<osho0000>
i have 20 more exercises to do till monday :D
<kerneis>
note a last trick: you could merge your last two patterns into a single one
<kerneis>
because they take the same variables and do the same thing
<kerneis>
just not in the same place
<yezariaely>
def-lkb: should $SHARE_DIR be defined in my environment by opam?
<kerneis>
s/last two/next-to-last two/
introom has quit [Remote host closed the connection]
<kerneis>
|Node((Node(_,c,_) as child),p,Nill) | |Node((Nill),p,(Node(_,c,_) as child)) when p > c -> check child
<kerneis>
but it's really the icing on the cake
<kerneis>
and you see now what I meant by "caml will warn you about a non-exhaustive pattern-matching"
<osho0000>
waw elegant
<osho0000>
brb launch :)
<kerneis>
it works only when you have *exactly* the same variables in each case
<kerneis>
see you
<def-lkb>
yezariaely: with opam, share dir is probably ~/.opam/4.00.1/share but it is not exported in the environment
<yezariaely>
def-lkb: I found it, was just confused that it was defined here and wondered if it should be.
<yezariaely>
*not* defined here
<def-lkb>
yes… it would be really nice if you took time to take note of all those confusing things :)… we should fix that, but it is really time consuming
ccasin has joined #ocaml
<kerneis>
grr, the latest ocamlgraph with its broken Fixpoint API is available in opam
<kerneis>
btw, anyone willing to upgrade the opam package?
<yezariaely>
def-lkb: In what direction is the type shown approximated if it says (approx)?
<yezariaely>
is it a subtype? supertype? or unspecified?
<def-lkb>
if there is syntax or type errors
mcclurmc has quit [Remote host closed the connection]
<def-lkb>
(merlin tries to recover, but it's just an heuristic, and a weak one at the time)
<yezariaely>
def-lkb: so what does the heuristics do?
<def-lkb>
yezariaely: so, it's neither a sub or supertype, its the type of the well-typed expression closest to the cursor
<gasche>
Kakadu: I found the issue with your test
<Kakadu>
gasche: I thought you are not here
<def-lkb>
yezariaely: arguably quite weak, but it's just a quick'n'dirty fix, until we have a better way to recover from errors
* Kakadu
is listening
weie has joined #ocaml
<gasche>
the problem is that when the pretty-printer runs for the combinators
<yezariaely>
def-lkb: e.g.: the type of 1 + 2.5 would be approximated to int because 1 + <some int> is approximated?
<def-lkb>
yezariaely: yes
<gasche>
lots of memory is in use, because the combinator parsed allocated a lot
<gasche>
so the GC is slow
<gasche>
(tracing passes have a lot of work)
<yezariaely>
Thx
<gasche>
hm
<gasche>
in fact it's not the tracing
<gasche>
it's the fragmentation that kills you
<gasche>
so I added
<gasche>
Gc.compact ()
<gasche>
before "match ans with" in the right place
<gasche>
and the time of pretty-printing is now back to 10s as with LR parsing
<Kakadu>
I have tried Gc.compact only before executing parser combintaors
<Kakadu>
Also, what do you mean by 'right place'?
<gasche>
well before the right "match ans with" :]
librarian has left #ocaml []
weie_ has quit [Ping timeout: 240 seconds]
<gasche>
after the parser combinators have run
mcclurmc has joined #ocaml
introom has joined #ocaml
<gasche>
I know it is compaction, because using Gc.full_major () instead doesn't work
<gasche>
note Kakadu that I think that is an artefact of the way you measure performances, by testing on a hughe input file
<gasche>
if you did lots of iterations on a file of the same sizes you will use in practice, you probably wouldn't observesuch a difference
<Kakadu>
gasche: Have you added it do TestHack.ml?
<kerneis>
I wont try to undestand that piece of code…
<rks`>
:D
dnm has joined #ocaml
<kerneis>
in fact, it's almost readable when syntax highlighted
<def-lkb>
kerneis: it depends on your terminal…
<def-lkb>
you can try :inoremap <Nul> <C-x><C-o>
<def-lkb>
it works on my current desktop, not on the previous one… I can't tell why :)
jbrown has quit [Remote host closed the connection]
<osho0000>
i simplified more the code but the result isnt still correct.. http://paste.in.ua/8604/
Agd_Scorp has joined #ocaml
<thizanne>
osho0000: 1 - 2 - 3 does 1 - (2 - 3)
<thizanne>
you want a - to be computed only with the next number, not the whole following expression
<osho0000>
ohh thanks
<osho0000>
let see :)
travisbrady has quit [Quit: travisbrady]
walter has quit [Quit: This computer has gone to sleep]
<osho0000>
thizanne have some idea maybe?
<thizanne>
I'm not sure giving you the solution is the best way to help
<thizanne>
maybe if you have a more precise question I can answer
shinnya has joined #ocaml
<osho0000>
hm.. don't know how to write the next number not all the expression
<thizanne>
you already wrote the following things :
<thizanne>
Nil, a Number n followed by Nil, a Number n follow by an operator followed by an expression
<thizanne>
then you want to wrote a Number n followed by an operator follow by another number n [and then stuff]
<osho0000>
you are saying that i must add more patterns..
<thizanne>
not necessarily
kaktus has quit [Remote host closed the connection]
<thizanne>
your pattern managing the '-' case is obviously wrong, so you have to modify it
<thizanne>
(before going further, do you plan to manage * and / ?)
travisbrady has joined #ocaml
ulfdoz has joined #ocaml
travisbrady has quit [Client Quit]
<osho0000>
thizanne no, only + and - :)
<osho0000>
in the - case maybe i must nest more patterns?
<thizanne>
that's a solution
<thizanne>
when you encounter a number then a '-', you know that you need to get the number following the - instead of the whole expression
<thizanne>
goind one step further in the pattern would give you this number
<osho0000>
ok i will try now
<osho0000>
thanks
<osho0000>
hm i can nest another expression but then the same problem appears in the next expression :)
<thizanne>
you don't need to nest another expression
<thizanne>
you only need to get the next number
mcclurmc has quit [Quit: Leaving.]
<osho0000>
i tried like this : Number(n,Oper('-',Number(g,h))) -> n - g + ovrednoti h
<thizanne>
something like | Number (n, Oper ('-', Number (p, expr))) -> ...
<thizanne>
ok
<thizanne>
then why "+ overdnoti h" ?
<thizanne>
maybe h starts with a -
<osho0000>
yes that s the problem
<thizanne>
and obviously you cannot nest it again
demonimin has quit [Ping timeout: 246 seconds]
<thizanne>
so what do you do when you must compute 1 - 2 + 3 ?
<osho0000>
i must put a + or a -
ben_zen has joined #ocaml
<thizanne>
your pattern is good
demonimin has joined #ocaml
<thizanne>
you cannot solve your problem by going one step further again, you would only shift it
introom has quit [Remote host closed the connection]
ben_zen has quit [Ping timeout: 256 seconds]
introom has joined #ocaml
<osho0000>
yes but don t know how.. i add a pattern |Oper(i,j) -> ovrednoti j but but for negative numers don't know.. because the same problem will arise..
<mrvn>
osho0000: negative numbers need a unary operator
<mrvn>
or 0 - a
nlucaroni has quit [Ping timeout: 245 seconds]
<thizanne>
osho0000: when you want to compute 1 - 2 + 3, you can compute 1 - 2, and replace this expression by the result
<thizanne>
so eval (1 - 2 + 3) is eval (-1 + 3)
<mrvn>
osho0000: You should change your code to type expr = Number of int | UnaryOp of char * expr | DualOp of char * expr * expr
introom has quit [Ping timeout: 264 seconds]
<thizanne>
mrvn: actually he only wants to manage + and -
<mrvn>
1 - 2 + 3 --> DualOp('+', DualOp('-', Number 1, Number 2), Number 3)
<osho0000>
mrvn I cant.. is a exercise of the exam
<mrvn>
The type is given?
<osho0000>
jp
<mrvn>
And what is the semantic? Is Number(10,Oper('+',Number(12,Oper('-',Number(4,Nil))))) --> 10 + (12 - 4)?
<mrvn>
From the type definition I would read that with parens like that.
<mrvn>
Number(10,Oper('-',Number(12,Oper('-',Number(4,Nil))))) --> 10 - (12 - 4) --> 10 - 8 --> 2. Your code is correct.
Xom has quit [Quit: ChatZilla 0.9.90.1 [Firefox 22.0/20130618035212]]
<osho0000>
no is (10+12)-4
<mrvn>
osho0000: That would not be expressable by your type
<osho0000>
are you telling me that I can do it?
<mrvn>
No, just the type definition is stupid
<osho0000>
ah ok :)
<mrvn>
Your type definition is right associative (iirc that is the correct phrase) and you want left associative.
<osho0000>
yes!
travisbrady has joined #ocaml
<osho0000>
in 3 hours i still dont find the solution..
<mrvn>
osho0000: you can do this with 2 recursive functions. The first gets an accumulator and expression, the other an accumulator, an operator and expression.
<mrvn>
And ovrednoti then takes the expression, extracts the first number and calls the first recursive function with it and the remaining expression
<osho0000>
ok.. i me tired now.. i thought that i can do it with modifaing my code but.. :)
<mrvn>
might be more readable with for loops and exceptions
<mrvn>
or Array.iter
<mrvn>
One wonders why the execrise uses char arrays instead of strings
asmanur has joined #ocaml
<mrvn>
I think for that exercise I would make an obscure solution. Build a list of all subarrays arrays of all jumps of the right length of the second string and then use List.mem or something.
<osho0000>
why max = ly / lx?
<mrvn>
osho0000: because step can't be more than ly / lx