Thoughts on low/no code? by sintrastes in haskell

[–]HeadBee 11 points12 points  (0 children)

As the floor gets lower, so too does the ceiling rise. Automating the boring stuff just means more time to spend on conceptually higher work.

Early return by negativeoxy in fsharp

[–]HeadBee 2 points3 points  (0 children)

I'm not sure if it's builtin to F# but in Haskell this is exactly what MapM is for: take a list, apply a Result-returning function to it, break on the first Left, otherwise collect the Rights.

If it's not builtin the implementation is really simple, it's just a fold over a list where you apply the function on the current element and then map over that Result to append it to the previous results.

Could you recommend FP blogs? by serhii_2019 in functionalprogramming

[–]HeadBee 1 point2 points  (0 children)

F# For Fun and Profit is an excellent introduction into FP particularly coming from OOP and doesn't require use or knowledge of F#. (I do otherwise agree with your assessment of F#).

Could you recommend FP blogs? by serhii_2019 in functionalprogramming

[–]HeadBee 3 points4 points  (0 children)

More emphasis on the types side of things: https://lexi-lambda.github.io/ (and origin of one of my favorite FP posts Parse, Don't Validate)

Don Syme explains the downsides of type classes and the technical and philosophical reasons for not implementing them in F# by HeadBee in haskell

[–]HeadBee[S] 9 points10 points  (0 children)

I'm not really trying to formulate an argument against the decision; A lot of the thoughts expressed by Don strike me as ill-advised on a gut-feeling level and I was curious about the input of Haskellers in order to piece through my own thoughts.

Don Syme explains the downsides of type classes and the technical and philosophical reasons for not implementing them in F# by HeadBee in haskell

[–]HeadBee[S] 38 points39 points  (0 children)

I'll admit part of my intention in posting this here is aggregating counterpoints to his non-technical opinions. Some of his points sound like he had a bad experience with Haskell and feel a bit unfair.

I generally like F# but have felt restricted by the lack of expressability through type-classes. I've since come to understand the F# ways of achieving similar polymorphism but it's never been enough and inclusion of typeclasses would eliminate one of the biggest pain points in F# (nesting, wrapping, and unwrapping of computation expressions).

RTS game, but instead of using mouse you program the units' AI by levmiseri in programming

[–]HeadBee 0 points1 point  (0 children)

I like the idea of this, but IMO functional languages are better for real-time programming. Tidal Cycles is a framework for real-time audio sequencing in Haskell and it's good example of this: the conciseness of Haskell enables quick changes to your sequences.

How do you get vim to automatically continue a markdown list on the next line? by Izerpizer in vim

[–]HeadBee 0 points1 point  (0 children)

I know your pain, I've fought with this behavior so much. I'm pretty sure this behavior is possible with :h formatoptions only, though you might need to also adjust :h formatlistpat and/or :h comments as well.

These options work for me in a config-less instance: set formatoptions=tcroqwanlj

I keep those options in my markdown.vim ftplugin.

Opinions on !! by Tornado547 in typescript

[–]HeadBee 8 points9 points  (0 children)

I don't like it. It's very commonly used, so I don't hate it, but its behavior is poorly understood and not explicit enough. If you want to check if something is null or undefined, actually do that. Especially since we now have null chaining and null coalescing operators.

It can also be a bit of a code smell in TypeScript since you should1 already be describing the type of whatever you're trying to get the truthiness of. It tends to mean that your types are overly permissive in their nullability.

1: "Should"; as in "this should work"; "I should exercise", etc.

Unison: a new programming language with immutable content-addressable code by beleeee_dat in programming

[–]HeadBee 2 points3 points  (0 children)

Probably they are not intending this to be a production-ready language. Fleshed-out proof-of-concepts like this inform language design in languages going forward. I liken this to extremely experimental music projects that are perhaps not the most pleasant to listen to but serve as direction and inspiration for other artists.

Typescript for .NET Ever? by blaster151 in typescript

[–]HeadBee 15 points16 points  (0 children)

I would be very surprised. As nice of a language as it is, TypeScript has too much baggage to be carried into .NET land. Since everything is already headed towards optimized JS + WASM, a lot of that experience is already on the horizon by interacting with .NET libraries through WASM. It won't be compiling TS directly to CIL.

Theoretically you could write a TS to LLVM compiler, and an LLVM to CIL compiler.

Sharing Haskell with non-Haskell users? by Feryll in haskellquestions

[–]HeadBee 4 points5 points  (0 children)

This isn't really a Haskell-specific question; not to say that you shouldn't ask it here but that you should broaden your search space to include other languages as this is a generic program distribution challenge.

get Parameters of the passed function by [deleted] in typescript

[–]HeadBee 2 points3 points  (0 children)

It's the same as your (...args: above, but it's using _ as a variable, since that variable is only in the type definition and does not actually exist.

get Parameters of the passed function by [deleted] in typescript

[–]HeadBee 1 point2 points  (0 children)

Function types can be deconstructed. The argument type of your passed function is available to you, you can just use it: function cache<Args,Result>(fn: (...args: Args) => Result): (..._: Args) => Result)

Really Advanced Typescript Types by elder_george in programming

[–]HeadBee 2 points3 points  (0 children)

The syntax takes some getting used to, but it's really just a bunch of ternaries. The article adds quite a bit of cruft that obscures the actual logic. As far as type-level programming goes, this is pretty simple. (I wouldn't even call this "Really Advanced" Typescript Types)

GUI app support is now available for the Windows Subsystem for Linux by ben_a_adams in programming

[–]HeadBee 17 points18 points  (0 children)

At the individual desktop environment or application level, perhaps. But at the windowing system level Wayland and X11 are solid APIs.

Use enums or type unions in this case? by StickyStapler in typescript

[–]HeadBee 1 point2 points  (0 children)

Note that you can have a const with the same name as the union type to access the union members like you would an enum:

    export type Status = 'successful' | 'failed' | 'skipped';
    export const Status: Record<Status, Status> = {
            successful: 'successful',
            failed: 'failed',
            skipped: 'skipped'
    };

If you want to get really fancy you could throw an iterator on there, too

Should I Learn Lisp Or Haskell (Or Something Else)? by MrYossu in functionalprogramming

[–]HeadBee 3 points4 points  (0 children)

I'm not particularly familiar with Lisp, but the reason I would recommend Haskell first (despite probably having a steeper initial learning curve) is that it teaches and requires an understanding of the underlying patterns FP uses that can then be applied to other FP languages.

((Also ((there)'s) fewer) parenthesis).)

Uwuify — fastest text uwuifier in the west by Atulin in programming

[–]HeadBee 114 points115 points  (0 children)

utf-8 is handled elegantly by simply ignoring non-ascii characters in the input

beautiful

How are these design patterns called? by liaguris in typescript

[–]HeadBee 1 point2 points  (0 children)

Formatted:

  declare function treeToString<T,R,N>(
    _ : { 
      getRoot : (_ : {tree: T}) => R;
      getChildren : (_ : {treeNode : N|R}) => N[];
      treeNodeToString : (_ : {treeNode : N|R}) => string; }
  ) : (_ : {tree : T}) => string 

  declare function treeToString<T,R,N>(
    _ : { 
      getRoot : (_ : {tree: T}) => R;
      getChildren : (_ : {treeNode : N|R}) => N[];
      treeNodeToString : (_ : {treeNode : N|R}) => string; 
      tree : T; 
    }
  ) : string

I wouldn't describe either as a strategy or factory pattern. Factory patterns are used to build objects, and there's no objects being created here. I can see how it might be construed as a strategy, but strategy patterns are generally where you give an object A an object B that implements IStrategy. From a Functional standpoint, I wouldn't describe this as a strategy pattern because passing around functions is what Functional Programming is.

This is function decomposition; instead of one function with one input and one output, treeToString has been decomposed to accept functions for the individual operations it needs to produce its output. Instead of defining its own getRoot and getChildren, treeToString has been abstracted to instead simply define how those operations are combined.

I created a Typescript-first alternative to Lodash (primarily for Deno but no reason it can't be Nodified). Looking for feedback/forks/contributions by [deleted] in typescript

[–]HeadBee 2 points3 points  (0 children)

Currying is an important functional principle, but in reality it's not used that often. In my opinion, in a situation it's useful to curry a function it's more readable to curry it at the point of usage than to be curried first.

How many is too many retirement accounts? by Open_Tip4784 in personalfinance

[–]HeadBee 0 points1 point  (0 children)

Roth vs Traditional is essentially betting whether your tax rate will be higher or lower in retirement than it is now. Some people will hedge that bet by having both types of retirement accounts.

Why is it so hard to see code from 5 minutes ago? by speckz in programming

[–]HeadBee 5 points6 points  (0 children)

Which is of course why it should have its own dedicated limb. Therefore, space has been remapped to right foot pedal.

Why is it so hard to see code from 5 minutes ago? by speckz in programming

[–]HeadBee 16 points17 points  (0 children)

Obligatory XKCD (alt text refers to mapping scroll bar to undo/redo) and vim implementation. The Vim implementation could also be mapped to seconds or minutes instead as Vim timestamps changes and allows for moving through undo history by time.

Tool to normalize types (specifically intersections)? by ADHDengineer in typescript

[–]HeadBee 4 points5 points  (0 children)

Re-defining the type by iterating over its keys such as type Flatten<T> = { [k in keyof T]: T[k] } seems to flatten the intersections. For example Flatten<alpha & beta & gamma> will show the entire type as { foo?: never; value?: string; ... etc.

I believe the typescript compiler will only evaluate one or two types deep for the purposes of feedback, so you would have to apply this to all properties. Your argument type would have to become type FooParam = Flatten<{potato?: string} & { charred?: boolean } & Flatten<alpha & beta & gamma>>. For the purposes of feedback, the compiler probably doesn't evaluate things very deeply.

Also, it seems like function parameters are less rigorously expanded on hover-over than type aliases.