Skip to content

idkjs/labdemo-re

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Create a Reason Record from Json

  • the goal of this project is to be able to use the the lab.json and theme.json files generated by compositor.io's lab project in a reasonml project.

Run

  • yarn then yarn start.

Questions

  • Decoding with bs-json returns a reason record type. Right?

StringMap Syntax fix:

  • implemented in src/DemoMap.re
  • This seems to work when operating straight of the raw json in Demo.x. If you decode to a record it works with component.name syntax as seen in src/Lab.components getComponentMap ().
let getComponentMap = myList =>
  List.fold_left(
    (map, component) => StringMap.add(component##name, component, map),
    StringMap.empty,
    myList,
  );
  • But then in src/LabTyped.re, it will throw error on component.name syntax and accept component##name syntax but then throws this type error.:
  /Users/prisc_000/code/REASON/EXPLORINGReML/labdemo-re/src/LabTyped.re 124:36-41

  122 │   );
  123 │
  124 │ let componentMap = getComponentMap(myList);

  This has type:
    list(Types.component)
  But somewhere wanted:
    list(Js.t(({.. name: StringMap.key} as 'a)))

  The incompatible parts:
    Types.component
    vs
    Js.t('a)    at <anonymous>
  • LabTyped Error #2
  104 │ };
  105 │
  106 │ let lab = labJson |> Decoder.decodeLab;
  107 │
  108 │ let components: list(Types.component) = lab.components;

  This has type:
    Js.Json.t => Types.lab
  But somewhere wanted:
    Js.t(({.. } as 'a)) => 'b

  The incompatible parts:
    Js.Json.t (defined as Js.Json.t)
    vs
    Js.t('a)

ninja: build stopped: subcommand failed.
  • So, something about list(Types.component) in LabTyped.re, (which I am assuming is a record type because we decoded it),that doesnt work with StringMap's String module. The difference between LabTyped.re and Lab.re is that in Lab.re I jump right to components by defining with components = lab##components; while in LabTyped.re I decode all of the lab.json then pull components off of the already decoded lab with components = lab.components
  • I can't quite get my head around this yet. Anyone? Anyone? Anyone?

Working Variant foolishness

  • It works but there must be a better way. See src/labdemo/DemoVariants.re

About

Trying to figure Reason, Belt, Polymorpic Variants..

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published