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

MigMit migmit at gmail.com
Wed May 24 13:01:49 UTC 2023


I don't think that's possible. Assume that there is a library that contains a module Stupid with a function osiudfhg, which is actually the same as fst:

module Stupid where
  osiudfhg :: (a, b) -> a
  osiudfhg (a, _) = a

If Alice uses that library, then her code could look like

main = putStrLn "print some magic number" >> print ( osiudfhg v )

How is Bob's code supposed to look? Maybe it should somehow replace "osiudfhg" with "x1_of", but how is it supposed to know that? It is a library function, after all.

Yes, it might analyze source code of the Stupid module, but this is a daunting task.

> On 24 May 2023, at 14:52, profited--- via Haskell-Cafe <haskell-cafe at haskell.org> wrote:
> 
> 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 ?
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.




More information about the Haskell-Cafe mailing list