racket-algebraic icon indicating copy to clipboard operation
racket-algebraic copied to clipboard

List applicative is wrong

Open Tuplanolla opened this issue 1 year ago • 0 comments

The applicative instance for lists does not behave the way it should. Compare the following Racket program with the Haskell program following it to observe the crucial difference.

#lang algebraic/racket/base

(require algebraic/control/applicative)
(require algebraic/data/list)

(with-instance list-applicative
  (<*> (list add1 sub1) (list 42 13)))
; '(43 12)

(with-instance list-applicative
  (<*> (list add1 sub1) (list 42 13 7)))
; map: all lists must have same size
main :: IO ()
main = do
  print ([(+ 1), (subtract 1)] <*> [42, 13])
  -- [43, 14, 41, 12]
  print ([(+ 1), (subtract 1)] <*> [42, 13, 7])
  -- [43, 14, 8, 41, 12, 6]

Tuplanolla avatar May 31 '23 09:05 Tuplanolla