Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the F# pipe symbol with an object constructor

I'm trying to figure out the correct syntax to use the pipe operator |> into the creation of an object. Currently I'm using a static member to create the object and just piping to that. Here is the simplified version.

type Shape = 
    val points : Vector[]

    new (points) =
        { points = points; }

    static member create(points) =
        Shape(points)

    static member concat(shapes : Shape list) =
        shapes
            |> List.map (fun shape -> shape.points)
            |> Array.concat
            |> Shape.create

What I want to do ...

    static member concat(shapes : Shape list) =
        shapes
            |> List.map (fun shape -> shape.points)
            |> Array.concat
            |> (new Shape)

Is something like this possible? I don't want to duplicate code by repeating my constructor with the static member create.

Update Constructors are first-class functions as of F# 4.0

In F# 4.0 the correct syntax is.

    static member concat(shapes : Shape list) =
        shapes
            |> List.map (fun shape -> shape.points)
            |> Array.concat
            |> Shape
like image 968
gradbot Avatar asked Feb 10 '09 05:02

gradbot


People also ask

Is it OK to say the F word?

The f-word can be a very hurtful, offensive, mean, and/or vulgar word. However, in adults' conversations and certain situations, it can serve as a comic relief, a colorful method of expressing frustration, surprise, astonishment and friendly-exclamation amongst many other things.

Why do people use the F word constantly?

A lot of times when we use the dirty words against others, it might be an indication of our frustration level. Abusing or cursing is a unique way to express our anger, desperation or even defeat. This may be still a taboo and certainly considered as a breach of social etiquette.

When did the F word become offensive?

Historians generally agree that "fuck" hit its stride in the 15th and 16th centuries as a familiar word for sexual intercourse, and from there it evolved into the vulgarity we know today.

How do I stop saying the F word?

Just say more appropriate words rather than the really offensive ones. For example, instead of saying the F word, say, "Flipping" or "Freaking" or "Fudge" or "Frickin", and for the S word, "sugar", "shoot", "shiz", "shingles", "crap" or "crud."


1 Answers

There's always

(fun args -> new Shape(args))
like image 64
Brian Avatar answered Oct 03 '22 08:10

Brian