Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge ByteString and Text functions and types #39

Open
ddssff opened this issue Apr 12, 2023 · 7 comments
Open

Merge ByteString and Text functions and types #39

ddssff opened this issue Apr 12, 2023 · 7 comments

Comments

@ddssff
Copy link
Contributor

ddssff commented Apr 12, 2023

In order to eliminate duplicate code, all the ByteString and Text specific functions are merged into functions that have a type parameter b with the constraints forall b. (Pack b) =>. The forall, along with {-# LANGUAGE ScopedTypeVariables #-}, lets you use b in signatures throughout the function to refer to the exact type used in the main signature. Remove the B and T suffixes from all functions and types. You may also need {-# LANGUAGE TypeFamilies #-}.

@ddssff
Copy link
Contributor Author

ddssff commented Apr 13, 2023

Also, I don't see much value in definitions like this:

emptySTRLESeq :: ST s (STRef s (Seq (Maybe b)))
emptySTRLESeq = newSTRef DS.empty

I would just replace uses of emptySTRLESeq with newSTRef DS.empty everywhere, and similarly for other functions. Furthermore, I don't think you need to encode the type in symbol names like brleseqstackempty - just call it stackRef, and rename brleseqstackemptyr just stack.

@Matthew-Mosior
Copy link
Owner

Matthew-Mosior commented Apr 13, 2023

@ddssff do you think we should move away from implementing via the ST monad right (replace with Writer monad)? If so a lot of these functions probably wont be necessary anymore. I still wonder about performance though, doesn't the ST monad allow for scoped mutation (should allow for a Haskellish way to maintain near C performance)? Maybe the current ST monad implementation isn't any faster than say implementing via the Writer monad (I like the Writer monad way much better).

@ddssff
Copy link
Contributor Author

ddssff commented Apr 13, 2023

Honestly, I don't understand how the ST monad affects performance. I did the writer monad implementation by incrementally transforming the ST monad implementation, so first I had to do the work described in this ticket - parameterize the ByteString / Text type, inline trival functions and types, etc. Once that is done we can convert to Writer monad but keep the ST monad version. Then perhaps some benchmarking.

@ddssff
Copy link
Contributor Author

ddssff commented Apr 13, 2023

My guess is that high performance is something you will have to do afterwards. But regular pure haskell does a pretty good job on its own.

@ddssff
Copy link
Contributor Author

ddssff commented Apr 13, 2023

One more suggestion - use pattern matching and the maybe function instead of fromJust and isNothing.

@Matthew-Mosior
Copy link
Owner

Sorry for the delay, will be looking into this soon.

@ddssff
Copy link
Contributor Author

ddssff commented Apr 20, 2023

No problem, I've been very busy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants