Jump to content

[Haskell] Construir strings e dps -> IO String


Recommended Posts

Posted

Eu tenho algo do genero:

a <- func1
((b,_):a) <- func2
let s1 = b
((b,_):a) <- func2
let s2 = s1 ++ b
((b,_):a) <- func2
let s3 = s2 ++ b

return s3

Só queria saber se ha forma de usar apenas uma variavel "s" em vez de usar "s1", "s2" e "s3" é que não tou a ver como... tentei algo como: let s = s + b, como funciona em certas linguagens, mas em haskell não funciona...

Posted

tentei algo como: let s = s + b, como funciona em certas linguagens, mas em haskell não funciona...

esse tipo de coisas só é possível quando existe um "estado".

em Haskell para teres um estado precisas de usar monads. em certas situações justifica-se, mas neste caso só ia complicar.

assim à primeira vista, podias simplificar isso se usasses 3 b's.

a <- func1
((b1,_):a) <- func2
((b2,_):a) <- func2
((b3,_):a) <- func2
return (b1++b2++b3)

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.