[Haskell-cafe] Converting Lists to Sets

Denis Bueno dbueno at gmail.com
Tue Feb 3 22:34:56 EST 2009


On Tue, Feb 3, 2009 at 14:58, rodrigo.bonifacio
<rodrigo.bonifacio at uol.com.br> wrote:
> Hi all,
>
> I'm trying to use the Funsat library. One of its data types is CNF:
>
> data CNF = CNF {
>  numVars :: Int
>  numClauses :: Int
>  clauses :: Set Clause
> }
>
> I have a list of clauses, but I'm getting an error when converting such a list to a Set. Using the fromList function, the ghc compiler reports that the fromList function is not applicable to literals.
>
> type Clause = [Lit]
>
> newtype Lit = L {
>  unLit :: Int
> }
>
> So, my question is: How can I solve this problem?

Assuming your list of clauses, you just need Data.Set.fromList:

    import qualified Data.Set as Set

    clauses :: [Clause]
    Set.fromList clauses :: Set Clause

                              Denis


More information about the Haskell-Cafe mailing list