equivalent of Haskell "error", and tuples

31 views
Skip to first unread message

Michael Mossey

unread,
Apr 12, 2018, 5:30:06 PM4/12/18
to purescript
In Haskell, I like to use "error" as a placeholder for computations that I haven't written out yet. The program will compile and type check on the other things and give me confidence I'm making progress. 

Is there an equivalent expression in Typescript, something that always typechecks and causes a run-time error if it's left in by mistake?

Also a second question: is there no tuple type in Typescript?

Mike

Brian Marick

unread,
Apr 12, 2018, 5:33:20 PM4/12/18
to pures...@googlegroups.com
> Also a second question: is there no tuple type in Typescript?

There’s no literal syntax, but there is a two-element tuple.

> import Data.Tuple
> Tuple 1 "foo"
(Tuple 1 "foo")

You can get multi-element tuples with Data.Tuple.Nested.


Alex Berg

unread,
Apr 12, 2018, 5:37:39 PM4/12/18
to pures...@googlegroups.com
I believe the general recommendation for error or undefined replacement is to use a hole,  like "?error" where ever you want it to just compile without an implementation. You can have many holes in one program.

--
You received this message because you are subscribed to the Google Groups "purescript" group.
To unsubscribe from this group and stop receiving emails from it, send an email to purescript+...@googlegroups.com.
Visit this group at https://groups.google.com/group/purescript.
For more options, visit https://groups.google.com/d/optout.

Michael Mossey

unread,
Apr 14, 2018, 4:25:52 PM4/14/18
to purescript
What's the syntax for a hole? "?error" gives a syntax error.

Alex Berg

unread,
Apr 14, 2018, 4:33:46 PM4/14/18
to purescript

```
module Main where

import Prelude

import Control.Monad.Aff.Console (CONSOLE)
import Control.Monad.Eff (Eff)


import Control.Monad.Eff.Console (log)

main :: forall eff. Eff (console :: CONSOLE | eff) Unit
main = ?test
```

Produces:

```
Hole 'test' has the inferred type Eff ( console :: CONSOLE | eff0 ) Unit You could substitute the hole with one of these values: Main.main :: forall eff. Eff ( console :: CONSOLE | eff ) Unit in value declaration main where eff0 is a rigid type variable bound at line 10, column 8 - line 10, column 8
```

Do you get something different?

Gil Mizrahi

unread,
Apr 14, 2018, 4:41:19 PM4/14/18
to pures...@googlegroups.com

I think the equivalent of Haskell's `error` in PureScript is `unsafeCrashWith`:

https://pursuit.purescript.org/packages/purescript-partial/1.2.1/docs/Partial.Unsafe#v:unsafeCrashWith

Michael Mossey

unread,
Apr 14, 2018, 10:14:16 PM4/14/18
to purescript
I guess it wasn't a syntax error, but, yes, I got that message, marked as an error and preventing compilation and running. My point is to place an expression there that typechecks and compiles and even allows me to run the program successfully if it never hits that expression. If it won't even compile there's no value to me.

Marcin Szamotulski

unread,
Apr 15, 2018, 2:03:28 AM4/15/18
to michae...@gmail.com, pures...@googlegroups.com
Hi Micheal,

The PureScript compiler doesn't know which code will run, and anyway deferring type errors to see if the code can be removed wouldn't be a good idea. Bottoms in Haskell are often considered as an antipattern, since it can happen that one accidentally leaves one, though indeed they are handy sometimes. If you really want it, there's nothing to stop you from providing one through ffi. But if you ever leave one, tracing a runtime error through endless stack of functions will likely let you rethink the idea ;)

Cheers,
Marcin


Sent from ProtonMail mobile



-------- Original Message --------

Michael Mossey

unread,
Apr 15, 2018, 2:13:01 AM4/15/18
to purescript
Hi Marcin,

I should have been more clear that first of all it's for very short-term checking, not something I would rely on for more than a couple hours. That doesn't prevent every mistake of course, but I should have also made clear I'm looking exclusively for the equivalent of "error," something which can be provided with a specific message that can be quickly located if accidentally left in.

Mike

Michael Mossey

unread,
Apr 15, 2018, 5:33:27 PM4/15/18
to purescript
That works, thank you.
Reply all
Reply to author
Forward
0 new messages