0
votes

Getting the error:

error FS0193: Type constraint mismatch. The type 
    'Map<ContentAndYear,DemoMap>'    
is not compatible with type
    'seq<ContentAndYear * DemoMap>

Problematic Code: Demo is where the error is occurring.

type Demo = Map<ContentAndYear,DemoMap>

type ContentAndYear = Content * Year

let demoMap =
    dataMap
    |> Seq.ofList
    |> Seq.map(fun (content, data) ->
        { Content = content
          Year = data.Year
          Person = data.Person
          NullContent = nullContent.[content].contentraw
          PercentContent = nullContent.[content].contentraw
        })
    |> List.ofSeq

let demolist = 
    demoMap
    |> List.map (fun x -> (x.Content,x.Year) |> ContentAndYear,x)
    |> Map.ofList 

let x = demolist |> Demo  <---- Problem Line

How to Solve? Not sure.

1

1 Answers

4
votes

Your type Demo is not a new type, but an alias for Map<ContentAndYear, DemoMap>, so your last line is completely equivalent to this:

let x = demoList |> Map<ContentAndYear, DemoMap>

The type Map<_,_> has a constructor that takes a seq<'key * 'value>, but you're trying to pass a Map<_,_> to that constructor, so naturally, the compiler complains.

How to solve this depends on what you actually meant.

Option 1: if your definition of Demo is what you actually intended, then demoMap is already of type Demo, so you can drop |> Demo completely:

let x = demoMap

Option 2: if you intended the last line to compile as it is, then you probably meant for Demo to be its own type, not an alias. That is to say, you meant for it to have a constructor that takes Map<ContentAndYear, DemoMap>:

type Demo = Demo of Map<ContentAndYear, DemoMap>

...

let x = demoMap |> Demo