r/purescript • • Aug 15 '17

Examples of Semigroups in PureScript. Also covers Records, Maybe and Folds.

Thumbnail
medium.com
8 Upvotes

r/purescript • • Jul 12 '17

Purescript: express, Aff, FS together

Thumbnail
medium.com
8 Upvotes

r/purescript • • Jul 04 '17

Purescript to find and print all 35 hexominoes

8 Upvotes

This is an adaptation of a Haskell program I wrote quite a few years ago. It finds and prints all 35 unique (under rotation and reflection) hexominoes. I wrote it mainly as a way of feeling out roadbumps and differences from Haskell in Purescript development.

Find and print all 35 Hexominoes

Because I'm new to Purescript, and haven't written any serious Haskell in years, I expect I've done some things the hard way. I would very much welcome suggestions on how to make this program more idiomatic, readable and concise.


r/purescript • • May 09 '17

Haskell and purescript remote job offer.

Thumbnail linkedin.com
8 Upvotes

r/purescript • • Apr 05 '17

Refactor imperative code to a single composed expression using Box

Thumbnail
medium.com
8 Upvotes

r/purescript • • Mar 01 '17

What is your opinion on Eff vs. mtl-style design?

8 Upvotes

Asking this here because PureScript is coming with Eff built-in so you people may have more experience in this field.

I recently started studying extensible effects and came across Oleg's "Freer Monads, More Extensible Effects" and the freer Haskell package. I read the paper, studied the implementation, and implemented my own effects and handlers (for logging, various limited versions of IO for interaction with a database, throwing exceptions, handling state etc.) and even implemented my own Eff monad (pretty much just a direct implementation of the idea described in the paper).

I liked it quite a lot. IO is all we do in the programs I work on these days, so I wanted monads with limited IO capabilities. For example, a monad for DB operations (without a MonadIO instance) etc. In addition, I need to be able to mock these monads. These are possible with mtl-style design, but it requires ridiculous amount of code and maintenance burden is just too much.

  • For every set of effects I need a class and some number of transformers + run functions (depending on how many concrete implementations for mocking etc. I need).

  • My transformers need instances for existing mtl-style classes.

  • Existing transformers need instances for my mtl-style classes.

  • Transformer stacks with multiple state, reader etc. monads are not easily possible (requires ridiculous amount of boilerplate).

In contrast, in Eff a mtl class becomes a GADT, and a transformer + run function becomes a handler function. This eliminates most of the boilerplate (handler functions still have some amount of boilerplate but that's because of how Eff is implemented in the paper and may be different in PureScript). Since effect definitions do not need to mention every other effect (something like "this effect can be combined with this other effect" which is basically what we do in mtl + transformers) effect definitions are much more concise. I can define a handler that runs a State a effect when a is provided and another handler that runs State a when IORef a is provided, given that I also have a IO in my effect signature (or some other effect that allows reading and modifying an IORef). Multiple State, Throw, Read etc. effects are easily possible with Proxy.

Overall I think it's a breath of fresh air, and I'm considering porting some of the libraries I use every day to Eff. But before that I want to ask about your experiences with Eff. PureScript has both Eff and mtl-style classes + transformers. What are your opinions on each? Do you prefer one over the other, or do you combine both depending on the requirements? What are the advantages of one over the other? (I know Eff is slower, but in my case that's not a huge deal as my programs are mostly IO-bound)


r/purescript • • Sep 27 '16

An Architecture for Modern Functional Programming: Part 2

Thumbnail
degoes.net
8 Upvotes

r/purescript • • Aug 30 '16

The midnight Monad, a journey to enlightenment

Thumbnail
lambdacat.com
8 Upvotes

r/purescript • • Aug 16 '16

Why are orphan instances strictly disallowed?

8 Upvotes

Background: For me, the orphan instance 'problem' arises often when I'm writing test modules. It would be nice to have something like import friend Data.X in the Test.Data.X module to write Arbitrary instances without having to write newtype wrappers.

In PureScript, orphan instances are disallowed "without any escape hatch": https://github.com/purescript/purescript/issues/1247

I'm not familiar with the discussion and would be interested in the arguments for (strictly) disallowing them.


r/purescript • • Feb 22 '16

Has anyone hacked around Electron using Purescript?

8 Upvotes

What are your thoughts? What are some common pitfalls and must have libraries.


r/purescript • • Jan 05 '16

ANN: QuickLift, a Haskell/PureScript single page app

Thumbnail parsonsmatt.org
8 Upvotes

r/purescript • • Dec 18 '15

ARoW.info Blog - PureScript for the Haskeller

Thumbnail arow.info
8 Upvotes

r/purescript • • Nov 21 '15

purescript-flare - A special-purpose UI library for PureScript

Thumbnail
github.com
8 Upvotes

r/purescript • • Oct 22 '15

Batteries 🔋 A PureScript prelude with more features

Thumbnail
github.com
8 Upvotes

r/purescript • • Oct 10 '15

Elm Architecture in PureScript III: Lists of Counters!

Thumbnail
parsonsmatt.org
8 Upvotes

r/purescript • • Jul 23 '15

PureScript/Haskell developer job opening @ Symbolian (Berlin) (x-post from /r/haskell)

Thumbnail
reddit.com
8 Upvotes

r/purescript • • Feb 13 '15

Purescript Compiler v0.6.7 - Scoped Type Variables, Rows in Instances and PSCI Improvements

Thumbnail
github.com
8 Upvotes

r/purescript • • Feb 08 '15

PureScript Compiler v0.6.5

Thumbnail
github.com
8 Upvotes

r/purescript • • Jan 08 '15

PureScript v0.6.3 released w/ MacOS, Linux and Windows binaries

Thumbnail
github.com
8 Upvotes

r/purescript • • Mar 01 '24

Calling a purescript entry point from JS

7 Upvotes

I am having trouble getting this to work. I am using halogen and loving it, but unfortunately, my initial use cases at work involve embedding the halogen app in existing pages.

If I don't add any parameters to my main function, then it runs fine, but that involves magically knowing the id of the wrapper div to highjack. When my entrypoint takes a string to use as that ID, the purescript doesn't run at all.

module App
  ( runApp
  ) where

import Prelude

import Data.Maybe (Maybe(..))
import Effect (Effect)
import Effect.Console (log)
import Halogen as H
import Halogen.Aff as HA
import Halogen.VDom.Driver (runUI)
import Query as Query
import Web.DOM.Document (toNonElementParentNode)
import Web.DOM.NonElementParentNode (getElementById)
import Web.HTML (window)
import Web.HTML.HTMLDocument (toDocument)
import Web.HTML.HTMLElement (fromElement)
import Web.HTML.Window (document)

runApp :: String -> Effect Unit
runApp id = HA.runHalogenAff do
  H.liftEffect $ log ("Purescript main received '" <> id <> "' as target element id.")
  w <- H.liftEffect window
  d <- H.liftEffect $ document w
  maybeElem <- H.liftEffect <<< getElementById id <<< toNonElementParentNode $ toDocument d
  case fromElement =<< maybeElem of
    Just elem -> const unit <$> runUI Query.component unit elem
    Nothing -> H.liftEffect $ log ("Couldn't find element with ID: " <> id)

That is an example taking a string for the ID. The resultant JS unminified is:

var runApp = function(id2) {
  return runHalogenAff(discard7(liftEffect6(log("Purescript main received '" + (id2 + "' as target element id."))))(function() {
    return bind9(liftEffect6(windowImpl))(function(w) {
      return bind9(liftEffect6(document(w)))(function(d) {
        return bind9(liftEffect6(getElementById(id2)(toNonElementParentNode(toDocument(d)))))(function(maybeElem) {
          var v = bindFlipped11(fromElement)(maybeElem);
          if (v instanceof Just) {
            return map25($$const(unit))(runUI2(component2)(unit)(v.value0));
          }
          ;
          if (v instanceof Nothing) {
            return liftEffect6(log("Couldn't find element with ID: " + id2));
          }
          ;
          throw new Error("Failed pattern match at App (line 27, column 3 - line 29, column 76): " + [v.constructor.name]);
        });
      });
    });
  }));
};

Running it with a test index.html like this:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>QueryMe</title>
  </head>
  <body>
    <script type="module">
      import { runApp } from '/index.js';
      let target = document.createElement('div');
      let body = await document.body;
      const id = 'app-target';
      target.id = id;
      body.appendChild(target);
      console.log('Starting purescript main...');
      runApp(id);
    </script>
  </body>
</html>

I get the message logged to the browser console from the JS in index.html, but appRun never appears to run.

If I assume the target id, and export an appRun of type Effect Unit, it works fine, and I get JS like this in the output:

var runApp = /* @__PURE__ */ function() {
  return runHalogenAff(discard(discardUnit)(bindAff)(liftEffect6(log("Purescript main received '" + (id2 + "' as target element id."))))(function() {
    return bind9(liftEffect6(windowImpl))(function(w) {
      return bind9(liftEffect6(document(w)))(function(d) {
        return bind9(liftEffect6(getElementById(id2)(toNonElementParentNode(toDocument(d)))))(function(maybeElem) {
          var v = bindFlipped11(fromElement)(maybeElem);
          if (v instanceof Just) {
            return map25($$const(unit))(runUI2(component2)(unit)(v.value0));
          }
          ;
          if (v instanceof Nothing) {
            return liftEffect6(log("Couldn't find element with ID: " + id2));
          }
          ;
          throw new Error("Failed pattern match at App (line 29, column 3 - line 31, column 76): " + [v.constructor.name]);
        });
      });
    });
  }));
}();

The FFI docs I found are pretty heavy on everything except passing arguments to entrypoints. I am exporting with spago bundle-module -m App (using -y normally, but I avoided minification for clarity while trouble shooting this issue.

For this first use case of purescript at work, I can rely on arcane knowledge of the correct div id, but it is very much not ideal and will conflict with hopeful future projects. Anyway, it seems like there is a weird edge case of behavior at the boundaries here, and I have wasted enough hours on it already to know I should ask for help. I am mostly new to purescript, but most of my work and leisure programming is done in haskell; so purescript seems pretty straight forward to me until encountering this behavior.

Thank you for your help. I hope I am just not thinking straight and there is some really simple reason I am messing up.


r/purescript • • Dec 28 '22

Anyone know what is wrong with my Vector3 Traversable instance?

Thumbnail
gallery
7 Upvotes

r/purescript • • Nov 11 '22

How to integrate with other framework and libraries ?

7 Upvotes

All the examples seem to be independent Purescript code. I did not find any example to manipulate DOM or to do an action when page load such as document.ready in jquery. I did not have the chance to work with Angular or React yet so maybe I'm missing something. Is the goal of purescript to be able to develop frontends that manipulate DOM and make AJAX calls? Is there any documentation about this use case? Thanks


r/purescript • • Jun 27 '22

Purescript Crud

7 Upvotes

Hi Everyone,

I'm new here and I'm looking a crud application in purescript where login and logout option available.

If any one have please share or share your reference where i can learn.

Best,
Shagun


r/purescript • • Jan 05 '22

Is PureScript good choice for prototyping?

7 Upvotes

I'm looking for language as close to type theory as possible, but that also easily targets browser, and has proper advanced feature support (webrtc, indexeddb) in libs, so that i can skip straight to app logic.

I like Agda, but i'm not ready to wrap all browser features myself yet. Haskell or Idris don't seem to have easy to start web-app ecosystem, either. I was told that Elm doesn't have anything (?) for that beyond accessing js API, which i'm trying to avoid. As js-first and fairly mature language, i wonder if PureScript is a good choice?

PS: i have basic js knowledge, but have a strong distaste for it and lack substantial for-browser coding. I tried PureScript a while ago, but didn't go beyond toying around, so i know i'm fine with the language, the question is only about environment/libs


r/purescript • • Oct 04 '21

Kind system

7 Upvotes

I'm trying to get a better grasp on the type system of purescript. One thing I'm struggling to fully understand is how the so-called "kind system" works. The language reference is very brief about it.

Are there other resources available (perhaps with more examples) that explain this?