I just started learning to code Haskell so apologies if this is a stupid question. I am trying to redo the eight queens problem by making use of the []
monad. Here is the code,
import Control.Monad
addqueen :: [Int] -> [[Int]]
addqueen xs = [ x:xs | x <- [1,2..8],
not $ x `elem` xs
|| (any (\ (index,q) -> abs (x-q) == index) $ zip [1..] xs) ]
When I try
[[]] >>= replicateM 8 addqueen
it does not work but yields the following error:
Couldn't match expected type `t0 -> t1' with actual type `[[a0]]'
The first argument of ($) takes one argument,
but its type `[[a0]]' has none
In the expression: [[]] >>= replicateM 8 $ addqueen
In an equation for `it': it = [[]] >>= replicateM 8 $ addqueen
So how do I achieve what I want to do here?
[[]]>>= replicateM 8 addqueen
to do. Note that[[]] >>= f
equalsf []
. – Johnettajohnetteiterate (>>= addqueen) [[]] !! 8
if I'm not mistaken. – Johnettajohnettefoldl (>>=) [[]] $ replicate 8 addqueen
– Replicate