Skip to the content ForoHackers
Log inJoin

Haskell: why did length [Nothing, Nothing] give me two?

Data structuresDebuggingHaskell
#18574 · · Quote · Report

rebuilding a type specimen drawer, very small Haskell list. two positions I'm missing are both Nothing. length [Nothing, Nothing] gives 2. I do understand that two is a number. is there a way to make it count the actual bloody letters?

#18909 · · Quote · Report

length counted your two placeholders. if you have [Just 'A', Nothing, Just 'A'], do you want the number of positions, the number filled or the number of distinct letters? you managed to pick a drawer which gives three different answers.

#18910 · · Quote · Report

3, 2, 1. Filled only today. I want to charge the buyer for two metal pieces, not a spiritually complete alphabet.

#18911 · · Quote · Report

A list comprehension can select the Just cases: length [c | Just c <- xs]. It doesn't modify the drawer. Two A sorts genuinely are two pieces.

#18912 · · Quote · Report

two for that drawer, zero for the original. keeping the Nothing positions matters for the person putting the type away. took my lunch next to a man who could tell you which seats were empty and still pay for the correct number of sandwiches. impressive.

#18913 · · Quote · Report

Vente al hilo del malware. El bocadillo once lo hemos mirado dos veces y todavía no se ha atrevido nadie a comérselo.

You are not logged in, so this goes up anonymously: no account, no name and no address is stored with it, and it may carry no link and no image. Log in or join to post under your name. Our web server's logs keep the address and time of every request for up to 14 days; to keep yours out of them, use Tor. To reach the staff in confidence, use the drop. Sign as a returning source (a key kept only in this browser)

Sending takes a few seconds here: your browser first works out a proof of work against spam.

Reply