Last active
September 5, 2019 18:23
-
-
Save f-f/757bef76c41d6ee17bec3ccc5fe7e271 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- | |
So this Dhall is basically JSON + functions + imports + types | |
More info on the official website, you can see some examples there: https://dhall-lang.org/ | |
I'll try to model in Dhall the YAML schema with embedded lispy you described me, | |
hoping to show how consistent it gets. | |
-} | |
-- You mentioned having a schema for the students there, I'll make up a type for it | |
-- Here's a sum type describing the majors: | |
let Major = < ComputerScience | Algebra | Music > | |
-- and here's a record type for a Student: | |
let Student = { name : Text, GPA : Double, major : Major } | |
-- Then you mentioned message templates. Dhall has string interpolation so it can do templating: | |
-- And I assume every program has a template with some "rules" associated with it | |
-- These rules can be modeled as "functions" that take e.g. the Student in input and return a Bool | |
-- (which would be True if the rule triggers) | |
-- First let's define the type of a Program (we don't really need to, but just for clarity) | |
-- Note: these arrows here are function types. So here `template` takes a Student and return a Text, | |
-- and we have a list of rules for that take a Student to decide if they trigger | |
let Program = | |
{ template : Student -> Text | |
, rules : List (Student -> Bool) | |
} | |
let programs = | |
{ bestStudents = | |
{ template = \(student : Student) -> "Hi ${student.name}, you're doing great!" | |
, rules = | |
-- Here we send this message only to students that have GPA higher than something. | |
-- These rules can be hardcoded here or they can come from wherever: e.g. | |
-- if they are composed by users that's totally secure because Dhall is not Turing complete | |
-- so it's safe to evaluate whatever function people inputs. | |
-- This part would be replacing the lispy thing | |
[ \(student : Student) -> student.GPA > 4.0 | |
] | |
} | |
} | |
-- Here we just return the programs, as the Haskell side could just interpret them | |
-- (and coding this interpreter would be like 20 lines, since there's a library for this already) | |
-- However, since Dhall's standard library has map, filter, etc the filtering for given programs could also | |
-- be done on the Dhall side, allowing to keep all the logic in an agnostic format! | |
-- In this latter case the Haskell side would only be triggering the side effects :) | |
in programs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment