Jump to content
joaopinto

erro em programa HASKELL BRAINFUCK

Recommended Posts

joaopinto

Boas estou a fazer um trabalho em Haskell e surgiu-me uma erro.

Este é o codigo:

instance Read BF where
readsPrec p s = case readsPrec p s of
                        [] -> [(BF [], s)]
                        xs -> [(BF (c:cs), u) |
                                   (c, t) <- xs,
                                   (BF cs, u) <- readsPrec p t]

instance Read BFCommand where
    readsPrec _ ('>':s) = [(IncPtr, s)] 
    readsPrec _ ('<':s) = [(DecPtr, s)]
    readsPrec _ ('+':s) = [(IncVal, s)]
    readsPrec _ ('-':s) = [(DecVal, s)]
    readsPrec _ (',':s) = [(Read, s)]
    readsPrec _ ('.':s) = [(Print, s)]
    readsPrec p s = [(While bf, v) |
                    ("[",t) <- lex s,
                    (bf,u) <- readsPrec p t,
                    ("]",v) <- lex u]

Ao insirir na consola (read "-" ) :: BFCommand devia me dar "DecVal" mas em vez disso da me "-".

Alguem me pode ajudar?

Share this post


Link to post
Share on other sites
Betovsky

Com consola referes ao interpretador?

Se sim, o que está a acontecer é que o interpretador executa o teu comando o que obtem um valor do tipo BFCommand. Ora o interpretador tem que mostrar esse valor ao utilizador, para isso verifica se esse valor implementa a class Show, para mostrar o resultado ao utilizador.

Agora vou presumir que tens a implementar a class Show para o tipo BFCommand e que caso seja um DecVal, esteja a retornar o '-'


"Give a man a fish and he will eat for a day; Teach a man to fish and he will eat for a lifetime. The moral? READ THE MANUAL !"

Sign on a computer system consultant's desk

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.