Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
  • Aug 06 11:50
    landy commented #56
  • Aug 06 11:32
    et1975 commented #56
  • Aug 06 08:35
    Build #122 passed
  • Aug 06 08:35
    landy opened #56
  • Aug 05 21:18
  • May 12 18:46
    Build #121 passed
  • May 12 18:45

    panesofglass on master

    Update Adds direct i… Merge pull request #55 from njl… (compare)

  • May 12 18:45
    panesofglass closed #55
  • Mar 30 23:16
    Build #120 passed
  • Mar 30 23:16
    njlr opened #55
  • Mar 30 23:12
    njlr forked
  • Jan 24 21:40
  • Jan 06 02:38
  • Dec 15 2019 20:06
    Mateiadrielrafael closed #54
  • Dec 15 2019 20:06
    Mateiadrielrafael commented #54
  • Dec 14 2019 16:30
    varon commented #54
  • Dec 08 2019 19:50
    Mateiadrielrafael opened #54
  • Nov 23 2019 12:00
    njlr edited #53
  • Nov 22 2019 23:41
    njlr opened #53
  • Nov 14 2019 15:39
    stroborobo closed #52
Alojzy Leszcz
all right - home time; have a good weekend !
Andrew Cherry
you too!
Alojzy Leszcz
Heya - interesting stuff found today:
        let inline serialise (x : 'a) = 
            (Chiron.Mapping.Json.serialize >> Chiron.Formatting.Json.format) x
and now:
> serialise [| 1; 2 |];;
val it : string = "[1,2]"
> serialise [| "1"; "2" |];;
System.TypeInitializationException: The type initializer for 'Escaping' threw an exception. ---> System.TypeInitializationException: The type initializer for '<StartupCode$Chiron>.$Chiron' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'FParsec, Version=, Culture=neutral, PublicKeyToken=40ccfc0a09edbb5d' or one of its dependencies. The system cannot find the file specified.
   at <StartupCode$Chiron>.$Chiron..cctor()
   --- End of inner exception stack trace ---
   at Chiron.Escaping..cctor() in C:\projects\chiron\src\Chiron\Chiron.fs:line 0
>    --- End of inner exception stack trace ---
   at Chiron.Escaping.escape(String s)
   at Chiron.Formatting.formatJson(Int32 level, JsonFormattingOptions options, Json _arg1) in C:\projects\chiron\src\Chiron\Chiron.fs:line 704
   at Chiron.Formatting.formatArray@710-1.Invoke(Json _arg1) in C:\projects\chiron\src\Chiron\Chiron.fs:line 710
   at Chiron.Formatting.join@667-2.Invoke(StringBuilder b) in C:\projects\chiron\src\Chiron\Chiron.fs:line 670
   at Chiron.Formatting.formatArray@708-4.Invoke(StringBuilder x) in C:\projects\chiron\src\Chiron\Chiron.fs:line 708
   at Chiron.Formatting.formatArray@708-5.Invoke(StringBuilder x) in C:\projects\chiron\src\Chiron\Chiron.fs:line 708
   at Chiron.Formatting.Json.format(Json json) in C:\projects\chiron\src\Chiron\Chiron.fs:line 743
   at <StartupCode$FSI_0005>.$FSI_0005.main@()
Stopped due to error
So serialising an array of ints works fine, but doesn't work with an array of strings.
Can you try it as well ?
Andrew Cherry
i'll have a look when i get a chance a little later! i'd start by seeing if i can work out why there's a file not found error for fparsec - that might well be related, but it's odd that it would be intermittent.
Alojzy Leszcz
ok - feel free to ignore this
I've just checked that after some paket-magic I had done, my project lost a reference to FParsec
After fixing that all fine
sorry for the false alarm
Andrew Cherry
no problem :)
Alojzy Leszcz
Heya - about the unit feature testing: so far so good
Andrew Cherry
:) sounds good!
Stefan Reichel
This message was deleted

With lenses and prisms, is there a guide in which it is appropriate to use either?. are prisms mainly for nested datastructures?. In freya the IfMatch_ header is returned as an IfMatch option Lens, rather than an IfMatch prism.

Say i wanted to deal with some nested values, it would make sense to use an epimorphism eg ifmatchweaktag_: Epimorphism<IfMatch,EntityTag.Weak>
But then with IfMatch itself being a Lens<IfMatch option> this doesn't compose.

I have written a composing epimorphism

      let private toPrism_ : Epimorphism<'T option, 'T> = (fun x -> x),
                                                            (fun v -> Some v)

but I'm not sure if this is idiomatic. I ask because I have my own lens in freya for the ClaimsPrincipal Lens<State,ClaimsPrincipal option>, which I can see the advantage for (eg my middeware could remove the claims principal if it wants to), but then most uses I can think of would want Prism<State,ClaimsPrincipal>.

@btrepp Andrew will have a better answer, but from my experience, there's no harm in providing both.
Especially if you're providing a library, it can be a lot easier to work with if the lenses/prisms already exist.
Jon Schoning

type Epimorphism<'a,'b> = ('a -> 'b option) * ('b -> 'a)
My understanding of epi is that it is morally surjective; wouldn't a function from 'a to 'b always have to succeed/produce a value then, because surjection means that the entire codomain receives a value?

Jon Schoning
i think it makes sense if we're considering the function from going from the preimage of 'a instead of the domain of 'a, then in that case there could be values in the domain of 'a that the function doesn't act on
Jon Schoning
epimorphism would look more like ('a -> 'b) * ('b -> NonEmptySeq<'a>)
Alojzy Leszcz
Hi Andrew. About the Defaults for unit type - no problems from my side. Just deployed a new version of my service to my testing environment. Should be safe to remove the "rc" label (hopefully I won't regret saying that ;) ).
Andrew Cherry
i haven't noticed any issues, so hopefully... :) i'll push to general release later when i get a moment!
Eugene Tolmachev
@kolektiv Aether gets a Fable build:
hope you don't mind
It's great to see Aether included in more places!
Maxime Mangel

Hello guys :)
Is it possible to write something like that:

        let m' =
          |> Optic.set (Model.Name_ >-> StringField.Value_) data.Name
          |> Optic.set Model.PatientPermissions_ data.PatientPermissions

My problem is the last line which is getting an error because Model.PatientPermissions_ don't have supported overload.
I could write it with standard record update but would look less "fluid" :)

Alojzy Leszcz
Hi guys,
The API I'm using returns one field that's an array of mixed types: sometimes it's a DateTime, sometimes it's a float. I think in order to deserialize it with Chiron I need to define a special F# type for it like:
type internal StringOrDecimal =
    | String of string
    | Decimal of decimal
But then I fail to create To/FromJson methods for the type. I've tried something like this:
    static member ToJson (x: StringOrDecimal) =
        match x with
        | String arg -> Json.String arg
        | Decimal arg -> Json.Number arg
but obviously the type of the function is incorrect. Any help with that ?
An example of the field that the API returns:
"data": [ [ "2016-12-04",  767.99, 750.0, 758.995, 760.519, 760.519, 760.111, 2376697.26975, 3137.22338 ] ],
You probably want to write some dynamic type checking:
match x with
| :? string as s -> ...
| :? int as i -> ...
| _ -> ...
Alojzy Leszcz
I'm not sure - this would result in having the ToJson of type: obj -> Json<unit>. I don't think providing To/From Json for obj is a good practice.
Later I'll take a deeper look into Chiron source code - for sure I'll find some hints there.
The only valid type for an array that holds differently typed things IS obj.
Alojzy Leszcz
Well... that's arguable - I might just create a DU like the one I pasted above and use that to represent my array.
I'm afraid there is however a more serious problem with using obj - correct me if I'm wrong, but I think that in order to use Chiron, I need to put To/FromString definitions in the same assembly where my type is defined. That's why I can't really extend the obj type.
(Again - as I said, correct me if I'm wrong).
Vladimir Sapronov
Hello Folks! I'm looking for some pure F# library for json (de)serialization. I'm working at some a big F#-based tech-company, so I wonder if I can get quick answers. I also viewed unit tests for Chiron, but I can't find docs, do you have some?
Also: Does Chiron use reflection? Is there any way to customize names of properties that record will be serialized to (without writing full ToJson/FromJson), smth like JsonProperty attribute in Newtonsoft?
Maxime Mangel
@vsapronov Hello, you can find some documentatio on how to use Chiron here:
I think you will have to write the ToJson/FromJson because it's "your job" to write how the Json will be wrote
Jonathan Fishbein
Francois Brodeur
Hi. I'm trying to use something similar to the Epimorphism example but reversed. On the website, the record field is of type string and we transform a Lens<Record, string> into a Prism<Record, int> via an Epimorphism<string, int>.
In my case, my record's field is an integer but the value will be a string. So I would want basically the setter to be protected. Does that make sense?
@FrankBro is an optic with a protected setter really an optic?
You can't really achieve composition with it. I'd generally advise either using a prism to handle the possibility of failure, or just a plain-old function.
Francois Brodeur
Alright, you might be right. I'll rethink this.
Alexandr Sugak
Hello! How can I generate json with duplicated keys (don't ask me why) using Chiron ?
E.g. I want this to produce json with two "bar" keys, each with its own value:
    type MyType =
            A: string
            B: (string*int) list
        static member ToJson(t: MyType) =
            let writeB bs j = bs |> List.fold (fun json (b1, b2) -> json *> Json.write b1 b2) j
            Json.write "a" t.A
            |> writeB t.B

    let b = {A="foo";B=[("bar", 1);("bar", 2)]}
    b |> Json.serialize |> Json.format