f#

Help in designing a tree structure - Tension between functional and OOP

北慕城南 提交于 2019-12-12 08:08:58
问题 I've been learning f# in the previous days, writing a small project which, at last, works (with the help of SO, of course). I'm trying to learn to be as idiomatic as possible, which basically means that I try to not mutate my data structures. This is costing me a lot of effort :-) In my search for idiomatic functional programming, I have been trying to use as much as possible lists, tuples and record, rather than objects. But then "praticality beats purity" and so I'm rewriting my small

Why are functions bound to the first type they are passed

时光毁灭记忆、已成空白 提交于 2019-12-12 08:08:44
问题 I'm new to F#. I was messing around and I found something interesting and I was hoping someone could enlighten me as to what is going on behind the scenew. So I made the function: let my_func (x, y) = x + y . Then I called the function with the args 1 and 2 giving me 3 . This is what I expected to happen but when I passed two strings to my_func I got an error even though + is a valid operator with strings. I reran my code but this time only calling my_func with "cat" and " dog" which gave me

Using AutoMapper with F#

…衆ロ難τιáo~ 提交于 2019-12-12 07:48:53
问题 I'm trying to use AutoMapper from F#, but I'm having trouble setting it up due to AutoMapper's heavy use of LINQ Expressions. Specifically, the AutoMapper type IMappingExpression<'source, 'dest> has a method with this signature: ForMember(destMember: Expression<Func<'dest, obj>>, memberOpts: Action<IMemberConfigurationExpression<'source>>) This is typically used in C# like this: Mapper.CreateMap<Post, PostsViewModel.PostSummary>() .ForMember(x => x.Slug, o => o.MapFrom(m => SlugConverter

Ignore public/internal fields for NHibernate proxy

筅森魡賤 提交于 2019-12-12 07:45:51
问题 I have some entity types that I would like to lazy load. However, they have some internal (assembly) fields they expose, but are not used outside that class. These fields are compiler generated (F#) and I cannot change them. The an example exception is: NHibernate.InvalidProxyTypeException: The following types may not be used as proxies: Mappings.MTest: field id@47 should not be public nor internal I understand why NHibernate is doing this, and how having fields, if I accessed them, would

Defining static classes in F#

末鹿安然 提交于 2019-12-12 07:40:01
问题 Is it possible to define a static class that contains overloadable members in F#? let module bindings cannot be overloaded, even though they are compiled into static static members in static classes. type declerations can contain static members, but I don't know if the type itself can be made static. My current solution is to define a type with a private constructor and just use that. I'm wondering if there is a way I can define a static type as I want. 回答1: As Robert Jeppeson pointed out, a

Are units of measurement unique to F#? [closed]

孤人 提交于 2019-12-12 07:32:18
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I was reading Andrew Kennedy's blog post series on units of measurement in F# and it makes a lot of sense in a lot of cases. Are there

Available parallel technologies in .Net

做~自己de王妃 提交于 2019-12-12 07:32:06
问题 I am new to .Net platform. I did a search and found that there are several ways to do parallel computing in .Net: Parallel task in Task Parallel Library, which is .Net 3.5. PLINQ, .Net 4.0 Asynchounous Programming, .Net 2.0, (async is mainly used to do I/O heavy tasks, F# has a concise syntax supporting this). I list this because in Mono, there seem to be no TPL or PLINQ. Thus if I need to write cross platform parallel programs, I can use async. .Net threads. No version limitation. Could you

Are side effects everything that cannot be found in a pure function?

て烟熏妆下的殇ゞ 提交于 2019-12-12 07:31:40
问题 Is it safe to say that the following dichotomy holds: Each given function is either pure or has side effects If so, side effects (of a function) are anything that can't be found in a pure function. 回答1: This very much depends on the definitions that you choose. It is definitely fair to say that a function is pure or impure . A pure function always returns the same result and does not modify the environment. An impure function can return different results when it is executed repeatedly (which

Why is there no Seq.partition in F#

落花浮王杯 提交于 2019-12-12 07:27:22
问题 In F# we have List.partition and Array.partition which return a tuple of lists and a tuple of arrays respectively. so, why is there no Seq.partition returning a tuple of sequences? here is a very simple implementation: F# Snippets so... why isn't this part of the core? 回答1: In F# 4.0 (Visual Studio 2015), the core libraries are a lot more uniform than before, but they still do not come with an implementation of Seq.partition . You can find more about this in the F# language design discussion:

F#'s underscore: why not just create a variable name?

旧巷老猫 提交于 2019-12-12 07:26:36
问题 Reading about F# today and I'm not clear on one thing: From: http://msdn.microsoft.com/en-us/library/dd233200.aspx you need only one element of the tuple, the wildcard character (the underscore) can be used to avoid creating a new name for a variable that you do not need let (a, _) = (1, 2) I can't think of a time that I've been in this situation. Why would you avoid creating a variable name? 回答1: Interesting question. There are many trade-offs involved here. Your comparisons have been with