1

I'm trying to run the following code to get subsets of k-elements but getting variable not in scope:ksubsets Not exactly sure whY?

Code:

subsets :: [a] -> [[a]]
subsets [] = [[]]
subsets (x:xs) = [zs | ys <- subsets xs, zs <- [ys, (x:ys)]]


ksubsets k xs = [ys | ys<-subsets xs, length ys==k]
9
  • 1
    Exactly how do you run this? Commented Oct 6, 2019 at 22:01
  • :r then use ksubsets 3 [1,2,3,4,5] @WillemVanOnsem Commented Oct 6, 2019 at 22:02
  • and you did use a file to specify these functions? Or did you load these in ghci itself, since an :r will indeed clean the memory, and thus remove the ones not in the file. Commented Oct 6, 2019 at 22:03
  • 2
    ghci> :{, then copy-paste your lines, then ghci> :}. (that's multi-line input mode) Commented Oct 6, 2019 at 22:10
  • 2
    you probably have some mix-up. carefully create new file, and load it. :) Commented Oct 6, 2019 at 22:13

1 Answer 1

1

Summarizing the comments, and possible problems and solutions:

  1. There are no errors in your code, you can even try it online here
  2. If you are using a text editor, check if you save your changes.
  3. run ghci, and load your file

    $> ghci

    Prelude> :l path/to/your/file.hs

  4. It should compile fine.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the summary! Another problem i don't know how to solve, how would i filter subsets based on length of k elements? AGain, Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.