Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

[PureScript] Add module Undefined as dependency #676

Closed
DonaldKellett opened this issue Jan 16, 2019 · 4 comments
Closed

[PureScript] Add module Undefined as dependency #676

DonaldKellett opened this issue Jan 16, 2019 · 4 comments

Comments

@DonaldKellett
Copy link
Member

Unlike Haskell, PureScript does not have a polymorphic undefined value by default and enforces totality so it may be impossible to provide an initial solution that compiles in certain cases without resorting to ugly hacks such as Unsafe.Coerce.unsafeCoerce Prelude.unit. However, a handy module Undefined (source) with a value undefined has been made available in PureScript since April 2018 which does not appear to be available on Codewars. Please consider adding it as a dependency, thanks 😄

@kazk
Copy link
Member

kazk commented Jan 16, 2019

We use psc-package so a package needs to be the one in package-sets. purescript-undefined doesn't seem to be.

Is this package commonly used? It also needs to be compatible with 0.12 (May 2018).

See these issues and documentation

@kazk
Copy link
Member

kazk commented Jan 16, 2019

Maybe updating to v0.12.2 will help. It supports named type wildcards ?hole.

@kazk
Copy link
Member

kazk commented Jan 17, 2019

I might be wrong, but the package you're suggesting won't behave like Haskell's undefined. I think it will just give a runtime type error that it's not a function. And it's confusing because it'll be in JavaScript syntax.


I think ?undefined (or name that's more appropriate) is good enough.

PureScript

countSheep :: Int -> String
countSheep = ?undefined

won't compile and shows

Error found:
in module CountSheep
at src/CountSheep.purs line 9, column 14 - line 9, column 14

  Hole 'undefined' has the inferred type

    Int -> String

  You could substitute the hole with one of these values:

    CountSheep.countSheep  :: Int -> String


in value declaration countSheep

(I can see this can be annoying for more complex kata though)

Haskell

countSheep :: Int -> String
countSheep = undefined

will compile, but the error is

ErrorCall (Prelude.undefined
CallStack (from HasCallStack):
  error, called at libraries/base/GHC/Err.hs:79:14 in base:GHC.Err
  undefined, called at src/CountSheep.hs:4:14 in main:CountSheep)

@DonaldKellett
Copy link
Member Author

Good point - typed holes should provide a clearer error message than TypeError: CountSheep.countSheep is not a function (which is what happens when undefined = unsafeCoerce unit is used) which is arguably even less readable than a compilation error message. Naming it ?todo should get the message across to beginners that the code would compile once the hole is replaced with a sensible solution implementation.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants