Implement Valuable for all Value constructors

This commit is contained in:
Niels G. W. Serup 2024-10-06 13:11:36 +02:00
parent fa06f0685a
commit b84e45ed8f
No known key found for this signature in database
GPG Key ID: 38EEEBCE67324F19
1 changed files with 24 additions and 0 deletions

View File

@ -61,12 +61,36 @@ instance Valuable Bool where
Bool a -> a
_ -> error "unexpected"
instance Valuable Image where
toValue = Image
fromValue = \case
Image a -> a
_ -> error "unexpected"
instance Valuable ImageConversionSettings where
toValue = ImageConversionSettings
fromValue = \case
ImageConversionSettings a -> a
_ -> error "unexpected"
instance Valuable Template where
toValue = Template
fromValue = \case
Template a -> a
_ -> error "unexpected"
instance Valuable () where
toValue () = Empty
fromValue = \case
Empty -> ()
_ -> error "unexpected"
instance (Valuable a, Valuable b) => Valuable (a, b) where
toValue (a, b) = Tuple (toValue a, toValue b)
fromValue = \case
Tuple (va, vb) -> (fromValue va, fromValue vb)
_ -> error "unexpected"
instance Valuable a => Valuable [a] where
toValue = List . map toValue
fromValue = \case