git.iko.soy/rowtype-yoga/purescript-backend-optimizer
on main help sign in
72 lines 1.7 kB history raw
1-- @inline ConvertableOptions.convertRecordOptionsCons arity=6
2-- @inline ConvertableOptions.convertRecordOptionsNil always
3-- @inline export flub always
4-- @inline export flubImpl never
5module Snapshot.ConvertableOptions01
6 ( test1
7 , test2
8 , test3
9 , test4
10 ) where
12import Prelude
13import ConvertableOptions (class ConvertOption, class ConvertOptionsWithDefaults, convertOptionsWithDefaults)
14import Data.Maybe (Maybe(..))
16type Optional =
17 ( foo :: Int
18 , baz :: Maybe Boolean
19 )
21type All =
22 ( bar :: String
23 | Optional
24 )
26data Flub = Flub
28instance convertFlubBar1 :: ConvertOption Flub "bar" Int String where
29 convertOption _ _ int = show int
31else instance convertFlubBar2 :: ConvertOption Flub "bar" String String where
32 convertOption _ _ str = str
34else instance convertFlubBaz1 :: ConvertOption Flub "baz" Boolean (Maybe Boolean) where
35 convertOption _ _ bool = Just bool
37else instance convertFlubBaz2 :: ConvertOption Flub "baz" (Maybe Boolean) (Maybe Boolean) where
38 convertOption _ _ mb = mb
40else instance convertFlubDefault :: ConvertOption Flub sym a a where
41 convertOption _ _ a = a
43defaultOptions :: { | Optional }
44defaultOptions =
45 { foo: 42
46 , baz: Nothing
47 }
49flub
50 :: forall provided
51 . ConvertOptionsWithDefaults Flub { | Optional } { | provided } { | All }
52 => { | provided }
53 -> String
54flub provided = flubImpl all
55 where
56 all :: { | All }
57 all = convertOptionsWithDefaults Flub defaultOptions provided
59flubImpl :: { | All } -> String
60flubImpl _ = "???"
62test1 :: String
63test1 = flub { bar: "Hello" }
65test2 :: String
66test2 = flub { foo: 99, bar: "Hello" }
68test3 :: String
69test3 = flub { foo: 99, bar: "Hello", baz: Just true }
71test4 :: String
72test4 = flub { foo: 99, bar: 42, baz: true }