[Haskell-cafe] what are correct ways to translate haskell code ?

profited at tutanota.com profited at tutanota.com
Wed May 24 12:52:57 UTC 2023


let's consider this example
        Alice has 1.hs like this
                v :: (,) Int Bool
                v = (,) 0 False

                main :: IO ()
                main = putStrLn "print some magic number" >> print ( fst v )

        Bob download 1.hs from Alice

        Bob would like to change 1.hs to 2.hs
        Bob want the programs [ 1.hs 2.hs ] to behave the same

        the reason that Bob want to modify 1.hs may be
                Bob does not like the type (,) in 1.hs

        Bob has Vector_2.hs
                module Vector_2 where

                data Vector_2 a b = C a b

                x1_of :: Vector_2 a b -> a
                x1_of ( C x1 _ ) = x1

                x2_of :: Vector_2 a b -> b
                x2_of ( C _ x2 ) = x2

        Bob like his Vector_2.hs
        Bob thinks the Vector_2 shall be good enough to replace (,) in 1.hs

i want to create a translator.hs for Bob
        Bob tell the translator.hs that Bob want to replace (,) with Vector_2 in 1.hs
        translator.hs automatically translate 1.hs to 2.hs
        2.hs shall look like this
                import Vector_2
                        ( Vector_2 )
                import qualified Vector_2

                v :: Vector_2 Int Bool
                v = Vector_2.C 0 False

                main :: IO ()
                main = putStrLn "print some magic number" >> print ( Vector_2.x1_of v )

what shall i do ?


More information about the Haskell-Cafe mailing list