Thank you for the replies to my first post and my second post on this project. This question is basically the same question as the first, but with my code updated according to t
I can help with one of the errors.
F# generally binds arguments left to right, so you need to use either parentheses around the recursive calls to pContent
or a pipe-backward operator <|
to show that you want to evaluate the recursive call and bind the return value.
It's also worth noting that <|
is the same as your $
operator.
Content.Post
is not a constructor for a Post object. You need a function to accept a Post list and return a Post. (Does something from the List module do what you need?)
My first answer was completely wrong, but I'd thought I'd leave it up.
The types Post
and Content
are defined as:
type Content =
| Content of string
| Post of Post list
and Post =
{ headers : Header list
; content : Content }
Post
is a Record, and Content
is a Discriminated Union.
F# treats the cases for Discriminated Unions as a separate namespace from types. So Content
is different from Content.Content
, and Post
is different from Content.Post
. Because they are different, having the same identifier is confusing.
What is pContent
supposed to be returning? If it's supposed to be returning the Discriminated Union Content
, you need to wrap the Post
record you are returning in the first case in the Content.Post
case i.e.
$ fun h c -> Post [ { headers=h
; content=Content $ unlines c } ]
(F# is able to infer that 'Post' refers to Content.Post
case, instead of the Post
record type here.)