Skip to main content
added 169 characters in body
Source Link
Zgarb
  • 42.8k
  • 4
  • 79
  • 259

ApplicativeDo, 104 bytes

import Control.Applicative
z=ZipList
instance Monad ZipList where _>>=_=z[]
main=print$do a<-z[1];pure a

Try it online!

With ApplicativeDo, this prints

ZipList {getZipList = [1]}

Without it, it prints

ZipList {getZipList = []}

ZipList is one of the few types in the base libraries with an instance for Applicative but not for Monad. There may be shorter alternatives lurking somewhere.

ApplicativeDo, 104 bytes

import Control.Applicative
z=ZipList
instance Monad ZipList where _>>=_=z[]
main=print$do a<-z[1];pure a

Try it online!

With ApplicativeDo, this prints

ZipList {getZipList = [1]}

Without it, it prints

ZipList {getZipList = []}

ApplicativeDo, 104 bytes

import Control.Applicative
z=ZipList
instance Monad ZipList where _>>=_=z[]
main=print$do a<-z[1];pure a

Try it online!

With ApplicativeDo, this prints

ZipList {getZipList = [1]}

Without it, it prints

ZipList {getZipList = []}

ZipList is one of the few types in the base libraries with an instance for Applicative but not for Monad. There may be shorter alternatives lurking somewhere.

Source Link
Zgarb
  • 42.8k
  • 4
  • 79
  • 259

ApplicativeDo, 104 bytes

import Control.Applicative
z=ZipList
instance Monad ZipList where _>>=_=z[]
main=print$do a<-z[1];pure a

Try it online!

With ApplicativeDo, this prints

ZipList {getZipList = [1]}

Without it, it prints

ZipList {getZipList = []}