Good material to read on Map in F#
Please help with the following exercise:
what are good source of material can I read to understand how to use Map in F#?
I tried to understand how to use Map.
I tried:
let holidays =
Map.empty.
Add("Christmas", "Dec. 25");;
It works then I tried:
let holidays =
Map.empty.
Add("Christmas", "Dec. 25")
Add("Halloween", "Oct. 31");;
and it gave an error
I had to put a dot after the first Add statement like this:
let holidays =
Map.empty.
Add("Christmas", "Dec. 25").
Add("Halloween", "Oct. 31");;
I'm wondering why is that.
So then that means
let holidays =
Map.empty;;
is how we create a new map. But I want a map of type Map (Team, Points).
So I tried:
let exmaple =
Map.empty.
Add ("Superman", Points 8);;
val exmaple : Map<string,Points> = map [("Superman", Points 8)]
But this is of type map(string, Points) not map(Team, Points).
Also, How do I write "<" after map on stackoverflow so that things follow "<" do appear(that is why i use map() instead of map<>)?
Please help.
f#
add a comment |
Please help with the following exercise:
what are good source of material can I read to understand how to use Map in F#?
I tried to understand how to use Map.
I tried:
let holidays =
Map.empty.
Add("Christmas", "Dec. 25");;
It works then I tried:
let holidays =
Map.empty.
Add("Christmas", "Dec. 25")
Add("Halloween", "Oct. 31");;
and it gave an error
I had to put a dot after the first Add statement like this:
let holidays =
Map.empty.
Add("Christmas", "Dec. 25").
Add("Halloween", "Oct. 31");;
I'm wondering why is that.
So then that means
let holidays =
Map.empty;;
is how we create a new map. But I want a map of type Map (Team, Points).
So I tried:
let exmaple =
Map.empty.
Add ("Superman", Points 8);;
val exmaple : Map<string,Points> = map [("Superman", Points 8)]
But this is of type map(string, Points) not map(Team, Points).
Also, How do I write "<" after map on stackoverflow so that things follow "<" do appear(that is why i use map() instead of map<>)?
Please help.
f#
4
Have you read the documentation?.
– Lee
Jan 3 at 0:42
Please help, you know when you start an assignment and you have no idea what is going on? How do I create a variable of type Map<Team,Points>? I tried :Map<Team "Vegeta", Point 5>;;, [("Vegeta", 10)];;, Map<Team, Points> [("Vegeta", 10)];; because I though Map<Team, Points> is a constructor.
– nafhgood
Jan 3 at 1:02
1
BTW, very good material to learn about F#: fsharpforfunandprofit.com
– AMieres
Jan 3 at 3:56
thanks! Also, do you know how to iterate through elements in a map like a::af for list?
– nafhgood
Jan 3 at 14:40
add a comment |
Please help with the following exercise:
what are good source of material can I read to understand how to use Map in F#?
I tried to understand how to use Map.
I tried:
let holidays =
Map.empty.
Add("Christmas", "Dec. 25");;
It works then I tried:
let holidays =
Map.empty.
Add("Christmas", "Dec. 25")
Add("Halloween", "Oct. 31");;
and it gave an error
I had to put a dot after the first Add statement like this:
let holidays =
Map.empty.
Add("Christmas", "Dec. 25").
Add("Halloween", "Oct. 31");;
I'm wondering why is that.
So then that means
let holidays =
Map.empty;;
is how we create a new map. But I want a map of type Map (Team, Points).
So I tried:
let exmaple =
Map.empty.
Add ("Superman", Points 8);;
val exmaple : Map<string,Points> = map [("Superman", Points 8)]
But this is of type map(string, Points) not map(Team, Points).
Also, How do I write "<" after map on stackoverflow so that things follow "<" do appear(that is why i use map() instead of map<>)?
Please help.
f#
Please help with the following exercise:
what are good source of material can I read to understand how to use Map in F#?
I tried to understand how to use Map.
I tried:
let holidays =
Map.empty.
Add("Christmas", "Dec. 25");;
It works then I tried:
let holidays =
Map.empty.
Add("Christmas", "Dec. 25")
Add("Halloween", "Oct. 31");;
and it gave an error
I had to put a dot after the first Add statement like this:
let holidays =
Map.empty.
Add("Christmas", "Dec. 25").
Add("Halloween", "Oct. 31");;
I'm wondering why is that.
So then that means
let holidays =
Map.empty;;
is how we create a new map. But I want a map of type Map (Team, Points).
So I tried:
let exmaple =
Map.empty.
Add ("Superman", Points 8);;
val exmaple : Map<string,Points> = map [("Superman", Points 8)]
But this is of type map(string, Points) not map(Team, Points).
Also, How do I write "<" after map on stackoverflow so that things follow "<" do appear(that is why i use map() instead of map<>)?
Please help.
f#
f#
edited Jan 3 at 1:19
nafhgood
asked Jan 3 at 0:21
nafhgoodnafhgood
1619
1619
4
Have you read the documentation?.
– Lee
Jan 3 at 0:42
Please help, you know when you start an assignment and you have no idea what is going on? How do I create a variable of type Map<Team,Points>? I tried :Map<Team "Vegeta", Point 5>;;, [("Vegeta", 10)];;, Map<Team, Points> [("Vegeta", 10)];; because I though Map<Team, Points> is a constructor.
– nafhgood
Jan 3 at 1:02
1
BTW, very good material to learn about F#: fsharpforfunandprofit.com
– AMieres
Jan 3 at 3:56
thanks! Also, do you know how to iterate through elements in a map like a::af for list?
– nafhgood
Jan 3 at 14:40
add a comment |
4
Have you read the documentation?.
– Lee
Jan 3 at 0:42
Please help, you know when you start an assignment and you have no idea what is going on? How do I create a variable of type Map<Team,Points>? I tried :Map<Team "Vegeta", Point 5>;;, [("Vegeta", 10)];;, Map<Team, Points> [("Vegeta", 10)];; because I though Map<Team, Points> is a constructor.
– nafhgood
Jan 3 at 1:02
1
BTW, very good material to learn about F#: fsharpforfunandprofit.com
– AMieres
Jan 3 at 3:56
thanks! Also, do you know how to iterate through elements in a map like a::af for list?
– nafhgood
Jan 3 at 14:40
4
4
Have you read the documentation?.
– Lee
Jan 3 at 0:42
Have you read the documentation?.
– Lee
Jan 3 at 0:42
Please help, you know when you start an assignment and you have no idea what is going on? How do I create a variable of type Map<Team,Points>? I tried :Map<Team "Vegeta", Point 5>;;, [("Vegeta", 10)];;, Map<Team, Points> [("Vegeta", 10)];; because I though Map<Team, Points> is a constructor.
– nafhgood
Jan 3 at 1:02
Please help, you know when you start an assignment and you have no idea what is going on? How do I create a variable of type Map<Team,Points>? I tried :Map<Team "Vegeta", Point 5>;;, [("Vegeta", 10)];;, Map<Team, Points> [("Vegeta", 10)];; because I though Map<Team, Points> is a constructor.
– nafhgood
Jan 3 at 1:02
1
1
BTW, very good material to learn about F#: fsharpforfunandprofit.com
– AMieres
Jan 3 at 3:56
BTW, very good material to learn about F#: fsharpforfunandprofit.com
– AMieres
Jan 3 at 3:56
thanks! Also, do you know how to iterate through elements in a map like a::af for list?
– nafhgood
Jan 3 at 14:40
thanks! Also, do you know how to iterate through elements in a map like a::af for list?
– nafhgood
Jan 3 at 14:40
add a comment |
1 Answer
1
active
oldest
votes
Three ways of creating an empty Map<Team,Points>
are:
let holidays : Map<Team, Points> = Map.empty
let holidays' = Map.empty : Map<Team, Points> // this also works
let holidays'' = Map.empty // even this works if followed by usage
You can add elements with either .Add(t, p)
or with Map.add t p
:
let twoAdded = holidays .Add("Superman", Points 6) .Add("Batman", Points 5)
let twoAdded' = holidays |> Map.add "Superman" (Points 6) |> Map.add "Batman" (Points 5)
The second way is the functional way.
Your type Team
and string
are the same because:
type Team = string
is just an alias not a new type.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54014876%2fgood-material-to-read-on-map-in-f%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Three ways of creating an empty Map<Team,Points>
are:
let holidays : Map<Team, Points> = Map.empty
let holidays' = Map.empty : Map<Team, Points> // this also works
let holidays'' = Map.empty // even this works if followed by usage
You can add elements with either .Add(t, p)
or with Map.add t p
:
let twoAdded = holidays .Add("Superman", Points 6) .Add("Batman", Points 5)
let twoAdded' = holidays |> Map.add "Superman" (Points 6) |> Map.add "Batman" (Points 5)
The second way is the functional way.
Your type Team
and string
are the same because:
type Team = string
is just an alias not a new type.
add a comment |
Three ways of creating an empty Map<Team,Points>
are:
let holidays : Map<Team, Points> = Map.empty
let holidays' = Map.empty : Map<Team, Points> // this also works
let holidays'' = Map.empty // even this works if followed by usage
You can add elements with either .Add(t, p)
or with Map.add t p
:
let twoAdded = holidays .Add("Superman", Points 6) .Add("Batman", Points 5)
let twoAdded' = holidays |> Map.add "Superman" (Points 6) |> Map.add "Batman" (Points 5)
The second way is the functional way.
Your type Team
and string
are the same because:
type Team = string
is just an alias not a new type.
add a comment |
Three ways of creating an empty Map<Team,Points>
are:
let holidays : Map<Team, Points> = Map.empty
let holidays' = Map.empty : Map<Team, Points> // this also works
let holidays'' = Map.empty // even this works if followed by usage
You can add elements with either .Add(t, p)
or with Map.add t p
:
let twoAdded = holidays .Add("Superman", Points 6) .Add("Batman", Points 5)
let twoAdded' = holidays |> Map.add "Superman" (Points 6) |> Map.add "Batman" (Points 5)
The second way is the functional way.
Your type Team
and string
are the same because:
type Team = string
is just an alias not a new type.
Three ways of creating an empty Map<Team,Points>
are:
let holidays : Map<Team, Points> = Map.empty
let holidays' = Map.empty : Map<Team, Points> // this also works
let holidays'' = Map.empty // even this works if followed by usage
You can add elements with either .Add(t, p)
or with Map.add t p
:
let twoAdded = holidays .Add("Superman", Points 6) .Add("Batman", Points 5)
let twoAdded' = holidays |> Map.add "Superman" (Points 6) |> Map.add "Batman" (Points 5)
The second way is the functional way.
Your type Team
and string
are the same because:
type Team = string
is just an alias not a new type.
edited Jan 3 at 1:39
answered Jan 3 at 1:33
AMieresAMieres
3,6501611
3,6501611
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54014876%2fgood-material-to-read-on-map-in-f%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
4
Have you read the documentation?.
– Lee
Jan 3 at 0:42
Please help, you know when you start an assignment and you have no idea what is going on? How do I create a variable of type Map<Team,Points>? I tried :Map<Team "Vegeta", Point 5>;;, [("Vegeta", 10)];;, Map<Team, Points> [("Vegeta", 10)];; because I though Map<Team, Points> is a constructor.
– nafhgood
Jan 3 at 1:02
1
BTW, very good material to learn about F#: fsharpforfunandprofit.com
– AMieres
Jan 3 at 3:56
thanks! Also, do you know how to iterate through elements in a map like a::af for list?
– nafhgood
Jan 3 at 14:40