I am building a small DSL for iOS' autolayout feature. Obviously I want to have a typesafe way to define autolayouts instead of doing VSL. I came up with the following://in reality this will be a Xamarin/iOS Viewtype View =      | Viewtype Constraint =      | Max of int     | Min of int     | Eq of int     | Both of int * inttype Element =     | Gap of Constraint     | Part of View * Constraintlet horizontal superview : Element list = []let max v = Max vlet min v = Min vlet eq v = Eq vlet minmax min max = Both(min, max)let gap c es = Gap c :: eslet view v c es = Part (v, c) :: es//transform needs to implement the real autolayouting.//not yet donelet transform es = List.rev eslet super_view, left_view, middle_view, right_view = View, View, View, Viewhorizontal super_view    |> gap (min 20)    |> view left_view (min 20)    |> gap (max 30)    |> view middle_view (eq 45)    |> gap (eq 50)    |> view right_view (minmax 20 100)    |> gap (max 0)    |> transformI am sort of content with the design so far; for example, it has a pretty fluid touch to it. However I am asking myself if there are better ways to do it. One particular issue is the simple fact that every definition is a intersection of gaps and views starting with a gap and ending with a gap. Is there a possibility to encode such a design into types instead of doing it via runtime exceptions (which I would do now).
DSL design for iOS Autolayout
f#;dsl