How to extract a Either's Right and keep information about its Left in case of error in Haskell? -


i trying extract value in right constructor of either value, while giving error if either in question left (i.e. error). answers in either right left how read value gives me like:

fromright e = either (const $ error "either left encountered while expecting right") id e 

this works discards useful information in error message of left ctor of either. how can post error message left instead?

-- edit --

thanks input. wanted more informational version of fromjust.

also, i'd avoid writing case statement every time, , want avoid monads whenever it's not complicated (to keep function "eval" style). use case, it's computation-oriented, , errors occur when invalid input supplied (when there no remedy).

i ended using:

fromright e = either (error.show) id e 

instead of using const ... in first argument of either, use else.

either oops ....   oops x = error $ "oops! got " ++ show x 

or whatever.


note, however, error should used internal errors. user errors, connectivity errors, etc., should allowed bubble out io , reported throwio or handled gracefully.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -