0

I am interested in implementing something like Freer Monads, more Extensible Effects in PureScript, but using rows rather than an open union (I suppose it is possible).

However, I wasn't able to define a kind without foreign import. I want to be able to do something like:

kind X
data Y :: # X -> Type -> Type

data Z :: X

Is that something I can do or should I look for another approach?

  • I don't understand the intended meaning of the `Log` type. – Fyodor Soikin Jun 14 '18 at 12:53
  • It represents an effect of logging a string, and the interpretation of that will be given later by a handler (eg, logging said string to IO or appending it to a file). – Jesper Dahl Jun 14 '18 at 13:38
  • If you want to keep `Log` in a type row, then it cannot have a string in it. PureScript is not dependently typed, so types cannot have values embedded. – Fyodor Soikin Jun 14 '18 at 17:31
  • Alright, but how do I say that `Z` is of kind `X`? (Edited `Log` to be `Z` now) – Jesper Dahl Jun 14 '18 at 17:42
  • You say `data Z :: X` – Fyodor Soikin Jun 14 '18 at 17:43
  • well, it doesn't work. It says it's a parsing error. :( – Jesper Dahl Jun 14 '18 at 17:58
  • Well, of course you also need to prefix everything with `foreign import`. You can't declare a `kind` like that, it has to be `foreign import`. And so do all `data` which are not `:: Type`. – Fyodor Soikin Jun 16 '18 at 03:39
  • My question was exactly if there is a way to do that without `foreign import` :( But thanks, don't wanna write the thing in javascript. – Jesper Dahl Jun 16 '18 at 05:03
  • That's a rather strange question. This is the syntax of the language, you can't use a different syntax. And why would you want to? – Fyodor Soikin Jun 16 '18 at 13:07
  • I know I can't use a different syntax than the one available. I would want to define a kind, types of that kind and inhabit such types, and most importantly without touching javascript for that. I couldn't find any documentation about kinds in purescript, except for a couple of lines that claim "user-defined" kinds -- what made me assume it were possible without `foreign import`. – Jesper Dahl Jun 16 '18 at 17:34
  • What I still don't see is what exactly prevents you from doing what you described. – Fyodor Soikin Jun 16 '18 at 20:40
  • I'd love to have pointers on how to do that then. – Jesper Dahl Jun 16 '18 at 20:53
  • What prevents you? What's the problem that you've encountered? – Fyodor Soikin Jun 16 '18 at 22:29
  • I don't know how to define a type of a specific kind and inhabit, for instance something like `data Z :: Type -> X = Zz a`. – Jesper Dahl Jun 17 '18 at 08:39
  • Only types of kind `Type` can be inhabited. You cannot inhabit a type of any other kind. – Fyodor Soikin Jun 17 '18 at 13:02
  • I guess that answers your question on what prevents me. – Jesper Dahl Jun 17 '18 at 13:39
  • I don't see why you'd need to inhabit non-`Type` types with values in order to do that. – Fyodor Soikin Jun 17 '18 at 17:46
  • Alright, as I saw from purescript-eff and related libs all function are defined as foreign import and a type of certain kind magically appears in the type signature. I don't want to define all my effects/effect functions as foreign import/in javascript, I want to define them in purescript. Do you have any pointers on how to do that? – Jesper Dahl Jun 18 '18 at 04:19
  • Nevermind, I just found out an implementation. – Jesper Dahl Jun 18 '18 at 15:11

1 Answers1

1

Nathan Faubion has an implementation of extensible effects, called purescript-run, using row polymorphism, variants and proxies.