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>
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>
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.