purescript-cookbook icon indicating copy to clipboard operation
purescript-cookbook copied to clipboard

Recipes that overlap with Book examples

Open milesfrain opened this issue 4 years ago • 2 comments

In today's meeting there were some recipe requests for FFI, Promises, and Logging with Monad Transformers.

Example of those can be found in these book chapters. https://book.purescript.org/chapter10.html https://book.purescript.org/chapter11.html

For example, here are the FFI and Promises examples (excluding exercise solutions): https://github.com/purescript-contrib/purescript-book/blob/master/exercises/chapter10/test/Examples.purs

Not sure if it makes sense to duplicate those here.

milesfrain avatar Jul 07 '20 00:07 milesfrain

I think you could both answer those type of questions while avoiding duplication of what the book covers on transformers and logging by having a concrete example of its use with Halogen/React/both.

For example, on logging, what's the most minimal example of when you'd reach for a concrete AppM (ReaderT Env Aff a) newtype for a Halogen app for logging (say with the logging mode dependent on the Env)?

Basically, pare Thomas's Realworld app all the way back to show just that one single aspect in a module:

  • The AppM newtype and its basic instances
  • A Logging class with a logMessage :: String -> m () method, the Logging AppM instance, and the lifted Logging (HalogenM ...) instance
  • One use of the Logging class's method within a component's handleAction/etc.
    • Keep it a simple logging example (like recording a button click) instead of something more complex like seen in the RoutingHashLog example
  • The unwrapping of the AppM type in your main function

Unless they were actually asking about the pure Writer-based logging like the book chapter covers?

and-pete avatar Jul 07 '20 03:07 and-pete

I had a look at the book and also at the documentation for purescript-aff and purescript-aff-promise - i think the lowest hanging fruit is to take the examples from the README's of those two libraries and make recipes out of the examples in them.

For example, reading the purescript-aff README suggests the following recipes (which, btw could then go back into purescript-aff as examples):

  • simplest use
  • wrapping an Effect with an Aff (ie wrapping a Purescript function)
  • the _ajaxGet example of wrapping a JS function using FFI
  • alt example for handling an alternative computation
  • monaderror (renamed as "handle an error in an async call" or something
  • bracket (renamed as "ensure cleanup of resources in event of cancelled async" or something like that)
  • fork
  • parallel

Likewise, the two examples on the purescript-aff-promise README suggest two great little self contained recipes:

  • Exposing promises
  • Consuming promises

afcondon avatar Jul 07 '20 06:07 afcondon