adrien changed the topic of #ocaml to: Discussions about the OCaml programming language | http://www.ocaml.org | OCaml 4.06.0 release notes: https://caml.inria.fr/pub/distrib/ocaml-4.06/notes/Changes | Try OCaml in your browser: http://try.ocamlpro.com | Public channel logs at http://irclog.whitequark.org/ocaml
FreeBirdLjj has joined #ocaml
FreeBirdLjj has quit [Ping timeout: 256 seconds]
FreeBirdLjj has joined #ocaml
andreas_ has quit [Quit: Connection closed for inactivity]
FreeBirdLjj has quit [Ping timeout: 260 seconds]
FreeBirdLjj has joined #ocaml
FreeBirdLjj has quit [Ping timeout: 248 seconds]
FreeBirdLjj has joined #ocaml
jao has joined #ocaml
FreeBirdLjj has quit [Ping timeout: 246 seconds]
FreeBirdLjj has joined #ocaml
orbifx1 has quit [Ping timeout: 256 seconds]
whoman has joined #ocaml
FreeBirdLjj has quit [Ping timeout: 240 seconds]
FreeBirdLjj has joined #ocaml
infinity0 has quit [Ping timeout: 256 seconds]
infinity0 has joined #ocaml
FreeBirdLjj has quit [Ping timeout: 256 seconds]
FreeBirdLjj has joined #ocaml
FreeBirdLjj has quit [Ping timeout: 264 seconds]
Nazral has quit [Quit: Changing server]
FreeBirdLjj has joined #ocaml
nicoo has quit [Ping timeout: 255 seconds]
nicoo has joined #ocaml
FreeBirdLjj has quit [Ping timeout: 268 seconds]
zolk3ri has quit [Remote host closed the connection]
FreeBirdLjj has joined #ocaml
silver has quit [Read error: Connection reset by peer]
baboum has quit [Quit: WeeChat 2.0.1]
FreeBirdLjj has quit [Ping timeout: 248 seconds]
FreeBirdLjj has joined #ocaml
pierpa has joined #ocaml
FreeBirdLjj has quit [Ping timeout: 240 seconds]
mfp has quit [Ping timeout: 248 seconds]
FreeBirdLjj has joined #ocaml
FreeBirdLjj has quit [Ping timeout: 248 seconds]
FreeBirdLjj has joined #ocaml
Haudegen has quit [Remote host closed the connection]
FreeBirdLjj has quit [Ping timeout: 260 seconds]
GreyFaceNoSpace has joined #ocaml
FreeBirdLjj has joined #ocaml
proteanthread has joined #ocaml
FreeBirdLjj has quit [Ping timeout: 248 seconds]
FreeBirdLjj has joined #ocaml
nicoo has quit [Remote host closed the connection]
nicoo has joined #ocaml
FreeBirdLjj has quit [Ping timeout: 264 seconds]
jao has quit [Ping timeout: 240 seconds]
ygrek has joined #ocaml
ziyourenxiang has quit [Ping timeout: 248 seconds]
pransmonkey has joined #ocaml
pransmonkey has quit [Ping timeout: 260 seconds]
govg has quit [Ping timeout: 264 seconds]
FreeBirdLjj has joined #ocaml
FreeBirdLjj has quit [Ping timeout: 268 seconds]
cobreadmonster has joined #ocaml
jbrown has quit [Ping timeout: 268 seconds]
FreeBirdLjj has joined #ocaml
govg has joined #ocaml
shinnya has joined #ocaml
sz0 has joined #ocaml
proteanthread has quit [Ping timeout: 264 seconds]
FreeBirdLjj has quit [Remote host closed the connection]
FreeBirdLjj has joined #ocaml
pierpa has quit [Quit: Page closed]
spew has joined #ocaml
ziyourenxiang has joined #ocaml
spew has quit [Read error: Connection reset by peer]
sz0 has quit [Quit: Connection closed for inactivity]
shinnya has quit [Ping timeout: 260 seconds]
kerrhau has quit [Ping timeout: 264 seconds]
cobreadmonster has quit [Quit: Connection closed for inactivity]
ygrek has quit [Ping timeout: 240 seconds]
mk9 has joined #ocaml
mk9 has quit [Quit: mk9]
jimmyrcom has quit [Ping timeout: 268 seconds]
kakadu has joined #ocaml
cbot has quit [Quit: Leaving]
mk9 has joined #ocaml
gpietro has joined #ocaml
sh0t has quit [Ping timeout: 240 seconds]
mk9 has quit [Client Quit]
FreeBirdLjj has quit [Remote host closed the connection]
zarul has quit [Ping timeout: 240 seconds]
Nazral has joined #ocaml
mfp has joined #ocaml
BitPuffin has joined #ocaml
FreeBirdLjj has joined #ocaml
slash^ has joined #ocaml
FreeBirdLjj has quit [Ping timeout: 264 seconds]
argent_smith has joined #ocaml
zolk3ri has joined #ocaml
orbifx1 has joined #ocaml
baboum has joined #ocaml
FreeBirdLjj has joined #ocaml
jnavila has joined #ocaml
kakadu has quit [Ping timeout: 246 seconds]
kakadu has joined #ocaml
TarVanimelde has joined #ocaml
jnavila has quit [Ping timeout: 256 seconds]
TarVanimelde has quit [Quit: TarVanimelde]
mk9 has joined #ocaml
mk9 has quit [Quit: mk9]
jnavila has joined #ocaml
jao has joined #ocaml
Haudegen has joined #ocaml
kakadu_ has joined #ocaml
kakadu has quit [Ping timeout: 256 seconds]
orbifx1 is now known as orbifx
slash_ has joined #ocaml
slash^ has quit [Ping timeout: 246 seconds]
shinnya has joined #ocaml
silver has joined #ocaml
zarul has joined #ocaml
mk9 has joined #ocaml
FreeBirdLjj has quit [Remote host closed the connection]
FreeBirdLjj has joined #ocaml
FreeBirdLjj has quit [Ping timeout: 240 seconds]
FreeBirdLjj has joined #ocaml
jao has quit [Ping timeout: 260 seconds]
FreeBirdLjj has quit [Ping timeout: 260 seconds]
zarul has quit [Ping timeout: 246 seconds]
donoban has joined #ocaml
<donoban> hi, I'm trying to rewrite a piece of code from a function pattern match to a list of records with variants
FreeBirdLjj has joined #ocaml
<donoban> I'm trying to add a record with variants fields to a list and I get this error
<donoban> Error: This expression has type [> `NetVM ] but an expression was expected of type Packet.host option
<donoban> Packet.host is defined as:
<donoban> type host = [ `Client of client_link | `Client_gateway | `Firewall_uplink | `NetVM | `External of Ipaddr.t ]
<donoban> I don't understand why `NetVM is not valid :\
<octachron> donoban, the type-checker is complaining about the missing option constructor in the type: you need to wrap your value in `Some x`
FreeBirdLjj has quit [Ping timeout: 248 seconds]
<orbifx[m]> Packet.host option means you are dealing with Some host | None.
<donoban> oh thanks
<donoban> yes I just tested removing option option and compiled
<donoban> but I need the all fields be optional
<orbifx[m]> Instead of making all the fields optional, why not make that value optional?
<donoban> its a rule_info type for a firewall
<donoban> it has, src, dst, dport, sport and protocol
<donoban> I want to be capable of define a rule using any number of fields
<donoban> i.e. using only dst address for accept/reject
FreeBirdLjj has joined #ocaml
<donoban> I'm not sure about the best way for achieve it
<orbifx[m]> Maybe use a Set
<donoban> I will take a look
<donoban> or maybe some ignore variant
<donoban> or ANY
FreeBirdLjj has quit [Ping timeout: 240 seconds]
<donoban> { src = `ANY; dst = `NetVM; `dport = `ANY; sport = `ANY; proto = `ANY }
<donoban> this seems more readalable than options and some constructions right?
zarul has joined #ocaml
<orbifx[m]> Quite
shinnya has quit [Ping timeout: 246 seconds]
FreeBirdLjj has joined #ocaml
dxtr has quit [Quit: leaving]
<donoban> once I have the list working and some func for doing pattern matching on it I would need to do it mutable
FreeBirdLjj has quit [Ping timeout: 240 seconds]
<donoban> could I define a mutable list or do I need to use refs? I found pretty confusing info about it
<orbifx[m]> Arrays are mutable, would that suit you?
<orbifx[m]> Or do you need to build it up?
orbifx has quit [Ping timeout: 240 seconds]
<donoban> sorry I don't know what you mean by building it up :\
<donoban> I would like to pass all rules from outside, I'm wodering if I could do something like:
<donoban> set_rules_list list = func
<donoban> rules_list <= list
<donoban> `OK
<donoban> I don't need to add or remove individual rules because they are all generated when there is some change and passed to Ocaml format using python
demonimin has quit [Ping timeout: 240 seconds]
FreeBirdLjj has joined #ocaml
<orbifx[m]> So you can create an array and store them there
<orbifx[m]> Array elements are mutable but my advise is to avoid mutability if you can.
<donoban> it's a unikernel firewall VM, https://github.com/talex5/qubes-mirage-firewall
<donoban> I need to add some mutability for reconfigure the firewall without recompiling and restarting it
orbifx has joined #ocaml
FreeBirdLjj has quit [Ping timeout: 248 seconds]
<donoban> currently it has the rules hard coded on it
FreeBirdLjj has joined #ocaml
FreeBirdLjj has quit [Ping timeout: 246 seconds]
<infinity0> companion_cube: did someone reply to nicole's comment on the functional iterators PR ocaml#1002 before they deleted their comment?
<donoban> ouch, I can't define dport : [ int | `ANY ];
<donoban> Error: The type int is not a polymorphic variant type
FreeBirdLjj has joined #ocaml
<donoban> maybe I have to use option there
mk9 has quit [Quit: mk9]
<Armael> You need to give a constructor for our int case
<Armael> Eg [ `Port of int | `Any ]
<donoban> uhM
<donoban> so a rule will be
<donoban> { src = `ANY; dst = `NetVM; `dport = `Port 53; sport = `ANY; proto = `ANY }
<Armael> Yes
<donoban> ok thanks
<donoban> I have doubt, since I'm editing an existing code I'm using `ANY, `NetVM...
<donoban> is there any difference with just ANY NetVM?
<Armael> `Any and `NetVM are just constructors with no argument
<Armael> I'm not sure I understand the question
<donoban> is anny difference between
<donoban> proto : [ `UDP | `TCP | `ICMP | `ANY ];
<donoban> or proto : [ UDP | TCP | ICMP | ANY ];
<donoban> what does `?
<Armael> Ah
<donoban> ah sorry I just read your answer
FreeBirdLjj has quit [Ping timeout: 256 seconds]
gpietro has left #ocaml ["Leaving"]
<donoban> using UDP I will be referecing a TAG name and `UDP is a new object of type UDP?
<donoban> hehe thanks :)
<Armael> Read the "polymorphic variants" section
jnavila has quit [Ping timeout: 264 seconds]
orbifx has quit [Ping timeout: 240 seconds]
orbifx has joined #ocaml
FreeBirdLjj has joined #ocaml
FreeBirdLjj has quit [Ping timeout: 240 seconds]
orbifx1 has joined #ocaml
orbifx has quit [Ping timeout: 246 seconds]
spew has joined #ocaml
spew has quit [Read error: Connection reset by peer]
sonologico has quit [Quit: WeeChat 1.9.1]
orbifx1 has quit [Quit: Quit]
GreyFaceNoSpace has quit [Quit: Ex-Chat]
pmetzger has joined #ocaml
antismap has joined #ocaml
whoman has quit [Ping timeout: 240 seconds]
spew has joined #ocaml
tane has joined #ocaml
ziyourenxiang has quit [Ping timeout: 248 seconds]
<companion_cube> infinity0: seems someone answered now
AnOddOne has joined #ocaml
AnOddOne has quit [Quit: leaving]
whoman has joined #ocaml
_y has joined #ocaml
jimmyrcom has joined #ocaml
<_y> has anyone else troubles installing alt-ergo 2.0 ?
<_y> more specifically http://paste.awesom.eu/u5an&ln
<_y> on the other hand alt-ergo 1.30 installs just fine
zolk3ri has quit [Ping timeout: 268 seconds]
<donoban> is it possible to match a list of record X with a record of type Y if X has a subgroup of fields from Y?
<donoban> maybe I can add a intermediate func for doing the comparison
<Armael> if you need to compare two records of different types, yes
<Armael> in a match, you can only match on a subset of the fields, though
<donoban> I have an info type, which is a real packet, and a rule_info, which only has some fields and them can be `ANY value
<Armael> (eg "match x with {a = 3; _} -> ..." will work even if x has more than one field "a")
<donoban> I'm trying to parse the list with a rec func
<Armael> ah I see; yes the solution is probably to write a separate matching function
zolk3ri has joined #ocaml
<companion_cube> wish we had view patterns
<Armael> that will encapsulate the logic about `Any
<donoban> I think the recursive way is hardening the problem
<donoban> better a func that compares a rule_info with info and returns rule_info.action
<donoban> oh I can leave the recursive way but avoid the use of match
jlouis has joined #ocaml
cobreadmonster has joined #ocaml
jnavila has joined #ocaml
spew has quit [Ping timeout: 268 seconds]
demonimin has joined #ocaml
wxyzzyrd has joined #ocaml
jnavila has quit [Ping timeout: 240 seconds]
pyx has joined #ocaml
pyx has quit [Client Quit]
jnavila has joined #ocaml
tane has quit [Quit: Leaving]
Haudegen has quit [Remote host closed the connection]
kerrhau has joined #ocaml
kerrhau has joined #ocaml
kerrhau has quit [Changing host]
BitPuffin is now known as webgl
webgl is now known as Muresan
Muresan is now known as Murii
Anarchos has joined #ocaml
Murii is now known as Allah
Allah is now known as BitPuffin
Haudegen has joined #ocaml
spew has joined #ocaml
slash_ has quit [Read error: Connection reset by peer]
Anarchos has quit [Remote host closed the connection]
Anarchos has joined #ocaml
cobreadmonster has quit [Quit: Connection closed for inactivity]
wxyzzyrd has quit [Ping timeout: 240 seconds]
wxyzzyrd has joined #ocaml
zolk3ri has quit [Remote host closed the connection]
dxtr has joined #ocaml
dxtr has quit [Ping timeout: 276 seconds]
BitPuffin has quit [Remote host closed the connection]
dtornabene has joined #ocaml
dxtr has joined #ocaml
spew has quit [Remote host closed the connection]
spew has joined #ocaml
orbifx has joined #ocaml
spew has quit [Ping timeout: 248 seconds]
spew has joined #ocaml
ewanas has quit [Quit: Leaving]
pmetzger has quit []
sonologico has joined #ocaml
spew has quit [Ping timeout: 256 seconds]
zarul has quit [Ping timeout: 260 seconds]
zarul has joined #ocaml
jnavila has quit [Remote host closed the connection]
dxtr has quit [Quit: leaving]
dxtr has joined #ocaml
ygrek has joined #ocaml
Anarchos has left #ocaml [#ocaml]
wxyzzyrd has quit [Ping timeout: 248 seconds]
spew has joined #ocaml
<donoban> on a record match pattern, should be possible to add multiple possible values for a field?
<donoban> like : { field_name = ( someVar | `Any ); _ }
<donoban> well, its a list of records for be accurately
spew has quit [Ping timeout: 260 seconds]
<thizanne> just kindly ask rks` and it will be.
<donoban> do you think? hehe
<octachron> using or-pattern works: "let f { contents = Some _ | None } = None"
<donoban> I don't see how to use it, do you mean using options?
<octachron> the problem in { field_name = someVar | `Any; _ } is that `Any is redundant since someVar can match anything
spew has joined #ocaml
spew has quit [Read error: Connection reset by peer]
<thizanne> wait it does work
<donoban> well someVar has already a value
<thizanne> I just tried and it didn't
<thizanne> oh, : instead of =, nvm
<donoban> match rule list with
<donoban> { rule_field : someVar } -> ...
<donoban> ?
<thizanne> you can't match a list against a record pattern
<Drup> donoban: that's not how pattern matching in OCaml work. You can't match against a pre-existing value. If you write a variable, it's a new variable
<donoban> hehe thanks, so I'm more lost than I believed
stux|RC-only has quit [Remote host closed the connection]
<donoban> I have a list of rules_info and a info_packet, both have common fields but not the same, how can I get the matching rule_info on the list? :\
<orbifx> donoban: I've been in and out today, so I've not familiarised with your problem enough
<donoban> hi orbifx , I'm trying to adapt a mirage unikernel
<thizanne> you can go through the list until you find some rule_info that matches
<donoban> which is a firewall for qubes, currently it has the firewall rules hard coded inside it, so if you want to modify some of them you have to rebuild and restart the virtual machine
<orbifx> Do you know about the `when` clause?
<thizanne> however that's a really simple function to code, so if you don't know how to do it and it took you (more than) a day, I suggest you properly learn ocaml first
<thizanne> it will probably save you a lot of time
<orbifx> I think thizanne's advice is good
<donoban> yes, I was reading some documentation until I though I had an easy way for doing it
<orbifx> It's nice to learn in the thick of it, but I think you have pulled too many features of the languages too suddently
<donoban> but then I started to typing code and... hehe
<companion_cube> and then ocaml also started typing code…
<donoban> I read something about when clause, there is some usecase on the existing code
<orbifx> I'm only mentioning `when` because you want to pattern much on something "variable"
<orbifx> But that's not to say this is what you should be doing given your overall problem.
<donoban> my problem is that I have some case of wildcard value, `Any
<thizanne> again donoban that's really not a hard function to write, so if it takes more than a few dozens of minutes (accounting for beginner's lack of "dexterity") you probably don't know OCaml enough
<donoban> with the current code, as a function, the rules just ignore the unwanted fields
<donoban> yes you are right thizanne , I will keep learning :)
<orbifx> where is your current code? your working branch or snippet
zarul has quit [Ping timeout: 248 seconds]
<donoban> I didn't push anything yet, I can pastebin if you want to check
<orbifx> I might get the picture quicker, but I've only got 5 mins
<donoban> there are few lines, 1sec
cbot has joined #ocaml
<orbifx> Also, are you aware of the forum?
<donoban> no I don't
<donoban> well I think I post most relevant
<donoban> I've add lol_ on rules_info type temporally for avoid name confusion
<donoban> line 82 has the current hard coded rules as a list
<donoban> at line 52 I was trying to write a func for get the matching rule for a packet
<donoban> I believed that using let { src = p_src; _ } = info in I could get the src of the real packet and use later on the match
<donoban> but It seems that I was wrong
<orbifx> just a minor thing, if you have matched in the second case you can ignore tl
<donoban> :: _ ?
<orbifx> yeah
<donoban> ok :)
<donoban> Im thinking I can't achieve this using match
<orbifx> And there is also a convention for readability where you can start a named variable with _ to state that you ignore it, e.g.: _tl
<orbifx> so you want the second clause to match on more complicated cases?
<orbifx> the second case*
<donoban> yes
<orbifx> ok
<donoban> e.g.
<donoban> match `Any or p_src value
<thizanne> (adding on orbifx, it's a convention also followed by the "unused variable" warning of the compiler, so it's worth following it)
<companion_cube> +1
<donoban> ty
<orbifx> thizanne: but if he was using _ the compiler would be equally happy, no?
<thizanne> indeed
<thizanne> but I wouldn't :(
<orbifx> yeah
<orbifx> donoban: you have two options
<orbifx> one you can write a rather involved `when` clause, where you can have boolean logic, call functions etc
<orbifx> or look at the List. scanning functions
<orbifx> List.exists looks like a good start
<donoban> ok
<donoban> I will study both
<orbifx> actually wait, you want the rule that matched right?
<donoban> only the action field
<orbifx> Then List.find will return the first element that matches satisfies your predicate function
<donoban> ok
<orbifx> Then you can take whatever fields you want from the returned record
<donoban> I'm gonna try first with when, but probably it will be pretty obfuscated code
<orbifx> yeah, I get the experiential value of that approach, but I'd not want to push that code :)
<donoban> hehe
<donoban> also is probably that later I will need to rewrite it as an array
<donoban> because I want the rules mutable
<donoban> I am not sure if I could use a mutable list or ref
<orbifx> Lists can be mutable too. Arrays are more compact in memory and have constant access time looking for random element.
<donoban> uhM, maybe performance is important here
<orbifx> Avoid mutability. I don't know if it's some kind of requirement for the unikernel, but it's a pandora's box for correctness :)
<donoban> do you know Qubes?
<orbifx> Just heard of it
<donoban> well, the real firewall rules are stored at Qubes dom0
<donoban> there is already a communication channel between the unikernel and qubes
<donoban> I want to start the firewall without any rule and then Qubes parse them to it
<donoban> is mutabililty needed right?
<orbifx> Not just from what you are saying
<orbifx> For lists you can just concat and yield a new list, which is really fast
<orbifx> For arrays it would need to copy every time you add an element, unless you know the size in advance
<donoban> but how I retain the rules in memory after qubes passes it to the kernel?
moei has quit [Quit: Leaving...]
<thizanne> donoban | uhM, maybe performance is important here
<thizanne> if so, you have absolutely no chance to get it right before learning OCaml :D
<donoban> well I don't need to do it right on the first time :)
<orbifx> donoban: are you planning to have shared C pointers or something to a memory shared with the Kernel? Is that how it works?
<donoban> I really don't need it for anything, just doing it for fun/learn
<donoban> uhm, no
<donoban> let me paste some code
ziyourenxiang has joined #ocaml
Haudegen has quit [Remote host closed the connection]
pierpa has joined #ocaml
<orbifx> donoban: I'm past my 5 minutes about 30 minutes ago :P
<donoban> hehe
<donoban> ok thanks
<orbifx> You should look at the mechanisms that Qubes has for exchanging data. Mutability is not a requirement in functional programming generally. In OCaml it tends to exist for certain optimisations.
zarul has joined #ocaml
<donoban> this is on the log of the unikernel
<orbifx> You can accumulate your state, or "change" it by returning new values and the runtime will collect (destroy) the old very efficiently
<donoban> I want to rewrite the python code which generates it, for generate the equivalent in a way that I can parse on Ocaml
<donoban> and then store as a list or array
<donoban> but well, it will take some time :)
<orbifx> Yeah. Try to find how to do it without mutability. It will affect your coding a lot.
ziyourenxiang has quit [Ping timeout: 256 seconds]
<donoban> I don't see how to now, but I will look
<orbifx> All the best. And welcome to OCaml. Note there is http://discuss.ocaml.org/ too, which might be more appropriate for big questions.
<donoban> ok ty
kakadu_ has quit [Remote host closed the connection]