nick8325 / nick8325/quickcheck

‘apply’ and ‘Fn’ for different arities

Open
#110 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discussion
Dominant language
Haskell
Stars
790
Forks
130
Avg merge
16h 41m
Merged PRs (30d)
2

Description

The following are used in containers

apply2 :: Fun (a, b) c -> a -> b -> c
apply2 f a b = apply f (a, b)

apply3 :: Fun (a, b, c) d -> a -> b -> c -> d
apply3 f a b c = apply f (a, b, c)

I see two directions we can go. We can supply those functions, along with:

pattern Fn :: (a -> b) -> Fun a b
pattern Fn f <- Fun _ f

pattern Fn2 :: (a -> b -> c) -> Fun (a, b) c
pattern Fn2 f <- Fun _ (curry -> f)

pattern Fn3 :: (a -> b -> c -> d) -> Fun (a, b, c) d
pattern Fn3 f <- Fun _ (curry3 -> f)

curry3 f a b c = f (a, b, c)

now it can be written

pInsertWithKeyStrict :: Fun (Int, Int) Int -> Int -> IntMap Int -> Bool
pInsertWithKeyStrict (Fn2 f) v m = isBottom $ M.insertWith f bottom v m

pInsertLookupWithKeyKeyStrict :: Fun (Int, Int, Int) Int -> Int -> IntMap Int -> Bool
pInsertLookupWithKeyKeyStrict (Fn3 f) v m = isBottom $ M.insertLookupWithKey f bottom v m

Alternatively we could use some type class trickery to provide a single function and pattern that supersede apply{,2,3} and Fn{,2,3}. So that the user never has to think about how many arguments their function has.

I have some doubts about the effects that will have on inference.


One last solution: somehow define an Arbitrary (Fun a (b -> c)) instance. I have not thought this through but if this makes sense it might be the most elegant solution.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by examining the existing Fun and apply entry points, then review the usage in tests/intmap-strictness.hs. Compare the proposed apply2/apply3 and Fn/Fn2/Fn3 APIs with the type-class and Arbitrary alternatives; done requires a decided approach with documented inference behavior and corresponding tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.