From b84e45ed8f26ab73a26cee79e03dd34157b973a7 Mon Sep 17 00:00:00 2001 From: "Niels G. W. Serup" Date: Sun, 6 Oct 2024 13:11:36 +0200 Subject: [PATCH] Implement Valuable for all Value constructors --- byg/src/Types/Value.hs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/byg/src/Types/Value.hs b/byg/src/Types/Value.hs index ab8461f..545c15a 100644 --- a/byg/src/Types/Value.hs +++ b/byg/src/Types/Value.hs @@ -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