Jump to content
Ruicrteixeira

instance Read

Recommended Posts

Ruicrteixeira

boas.

tenho como trabalho realizar uma instance show e read relativamente a manipulaçao de tipos.

como objectivo no show tenho que passar, por exemplo show (BF [Read, While (BF [Print, DecVal])]) vai ser igual a string ",[.-]", e read ",[.-]" vai ter como resultado BF [Read, While (BF [Print, DecVal])]

de codigo realizado (acho eu que correcto) tenho:

data BF=BF [bFCommand]
               -- deriving (Eq,Show)
data BFCommand =IncPtr  |DecPtr |IncVal |DecVal |Read |Print |While BF

instance Show BF where
    show (BF is)=concatMap show is

        
instance Show BFCommand where
        show IncPtr =  ">"
        show DecPtr =  "<"
        show IncVal =  "+"
        show DecVal =  "-"
        show Read   =  ","
        show Print  =  "."
        show (While s) = "["++show s++"]"

este realiza o pretendido, a minha duvida esta toda no read:


instance Read BF where
      readsPrec _ = readBF

agradecia que alguem me desse ajudas relativamente a completar a parte do read, pois nao sei como defenir o readBF.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.