Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Improve the documentation of partial functions in base #52

Open
sjakobi opened this issue Dec 29, 2016 · 9 comments
Open

Improve the documentation of partial functions in base #52

sjakobi opened this issue Dec 29, 2016 · 9 comments
Labels

Comments

@sjakobi
Copy link

sjakobi commented Dec 29, 2016

  • Emphasize in which cases the function will result in an error.

  • Point at total alternatives, e.g. head's documentation should mention listToMaybe.

@neongreen
Copy link
Member

I could do it (I recently made a patch to base and it wasn't hard) but first we should find a list of partial functions in base. Is there one somewhere?

@Gurkenglas
Copy link
Collaborator

Gurkenglas commented Jan 1, 2017

fromJust and head are eventually implemented using errorWithoutStackTrace, so you could search its call history in base source.

@neongreen
Copy link
Member

Makes sense, thanks.

@neongreen neongreen added the base label Jan 1, 2017
@sjakobi
Copy link
Author

sjakobi commented Jan 2, 2017

I could do it (I recently made a patch to base and it wasn't hard)

Sounds great! I think it's quite a bit of work, but definitely worth it!

There is also the issue of type class instances with partial methods. For example succ :: Integer -> Integer is for most purposes quite total while succ :: Bool -> Bool isn't.

Instances can have their own haddocks like the Read instance here but individual instance methods can apparently not.

@neongreen
Copy link
Member

neongreen commented Jan 2, 2017

I'm sleepy so I'll just dump the list here:

errorWithoutStackTrace:
  • printf
  • read
  • gather
  • showInt, showIntAtBase
  • intToDigit, digitToInt
  • mallocForeignPtr, mallocForeignPtrBytes, mallocForeignPtrAlignedBytes, 
    mallocPlainForeignPtr, mallocPlainForeignPtrBytes, 
    mallocPlainForeignPtrAlignedBytes, addForeignPtrFinalizer
  • (!!)
  • (^)
  • chr
  • NonEmpty: fromList, (!!)
  • stimes, stimesMonoid, stimesIdempotentMonoid, stimesIdempotent
  • bitSize @Integer, @Natural
  • complement @Natural, pred @Natural
  • fromJust
  • the
  • registerDelay
  • maximumBy, minimumBy, genericIndex, foldr1, foldl1, minimum, maximum
  • succ, pred, toEnum, fromEnum
  • repConstr, dataTypeConstrs, indexConstr, constrIndex, 
    maxConstrIndex, mkIntegralConstr, mkRealConstr, mkCharConstr
  • gunfold for various types (?)
  • readControlMessage, sendMessage
  • newDefaultBackend
  • dynApp
  • threadWaitRead, threadWaitWrite, threadWaitReadSTM, 
    threadWaitWriteSTM on Windows
  • mfix @Maybe, @Either

errorEmptyList:
  • head, tail, init, last, foldl1, foldl1', foldr1, maximum, minimum, cycle

error:
  • lots of functions in Data.Bifoldable

Probably missed something. Also some of those already have warnings, though it might be nice to make them more unified.

@Gurkenglas
Copy link
Collaborator

@neongreen
Copy link
Member

The Foldable [] instance uses maximum from GHC.List, which uses errorEmptyList.

@sjakobi
Copy link
Author

sjakobi commented Jan 24, 2017

FWIW the changes can now also be submitted via https://github.com/ghc/ghc/pulls.

@nikivazou
Copy link

How about adding Liquid Haskell type signatures to constrain the domain of the partial functions and make them total?

I believe that Liquid type specifications

  • are compact forma of documentation and also
  • are machine checked.

We have already specified many Base functions in here

https://github.com/ucsd-progsys/liquidhaskell/tree/develop/include

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

No branches or pull requests

4 participants