Skip to content

Refactor mutable generators#122

Merged
idontgetoutmuch merged 1 commit intointerface-to-performancefrom
refactor-mutable-gens
May 8, 2020
Merged

Refactor mutable generators#122
idontgetoutmuch merged 1 commit intointerface-to-performancefrom
refactor-mutable-gens

Conversation

@lehins
Copy link
Copy Markdown
Collaborator

@lehins lehins commented May 7, 2020

Main semantic change in this PR is the switch to TypeFamilyDependencies for Frozen, which until couple days ago I mistakenly thought can only be used with closed type families:

type Frozen g = (f :: *) | f -> g

This approach gives very nice usability improvements:

  • stateful random libraries like mwc-random do not have to define any newtypes (see the updated haddock), thus simplifying corresponding instances and overall making usage of MonadRandom more pleasant. I am sure @Shimuuar will approve of this approach
  • STGen , IOGen ... now get a standalone pure counterpart, which now have a constructor that is easily discoverable in haddock. With data family Frozen, instead of type family Frozen constructor is hidden from the user and can't really be documented directly

Besides semantic changes it contains some improvement to consistent naming. Each Monadic generator has now a suffix M, ie. IOGenM. Each monadic has a pure counterpart without M, ie. IOGen

PureGen is now renamed StateGen, which I think better describes its nature and how it works underneath

The important part of this PR is that everything else works just the same as before with respect to performance and type inference (without TypeFamilyDependencies Frozen would make types of some functions ambiguous and would drastically impact the usability, which was my main concern before and the reason for rejection of #67 )

@lehins lehins force-pushed the refactor-mutable-gens branch from cd272a0 to cd5421f Compare May 7, 2020 13:09
Copy link
Copy Markdown
Owner

@idontgetoutmuch idontgetoutmuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much nicer

Copy link
Copy Markdown
Collaborator

@curiousleo curiousleo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really neat. The names are all better now, the MonadRandom instances are more straightforward to write, and thanks for removing the obsolete primitive extra-dep!

@idontgetoutmuch idontgetoutmuch merged commit f2319cc into interface-to-performance May 8, 2020
@idontgetoutmuch idontgetoutmuch deleted the refactor-mutable-gens branch May 8, 2020 12:27
@Shimuuar
Copy link
Copy Markdown

Shimuuar commented May 8, 2020

I am sure @Shimuuar will approve of this approach

Yes, I do. Excellent idea

curiousleo pushed a commit that referenced this pull request May 19, 2020
Shimuuar pushed a commit to Shimuuar/random that referenced this pull request Jan 6, 2025
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

Successfully merging this pull request may close these issues.

4 participants