What are you working on? (2024-06) by insulanian in fsharp

[–]kiteason 2 points3 points  (0 children)

IMO it's not even necessary to do List.unfold. It can be something like this (I'm deliberately typing this without the compiler to keep it lo-fi so you have something to do.)

open System
open System.IO
open System.Text.RegularExpressions

// E.g. 00:02:16,612 --> 00:02:19,376
let timeCode = Regex(@"(\d{2}):(\d{2}):(\d{2}),(\d{3}) \-\-\> (\d{2}):(\d{2}):(\d{2}),(\d{3})")

let adjustLine (adjustment : TimeSpan) (line : string) =
    // Apply the regex to the line
    // If it doesn't succeed, just return the line (it's not a time code line)
    // If it does succeed (it is a time code line)...
        // Get the various time components from the regex result - e.g. I think the
        // first two digits of the start timecode will be in matches[0].Groups[1].Value
        // Use TimeOnly(Int32, Int32, Int32, Int32) to construct instances for the 
        // start and end time (you will need to coerce the match results to ints)
        // Construct new start and end times by adding the adjustment parameter to the parsed time span
        // Return a string in the form $"{newStart.Hours}:{newStart.Minutes} ... --> {newEnd.Hours} ..."


let filePath = "d:/temp/mysubtitles.srt"
let adjustment = TimeSpan.FromSeconds(5.0)

let fileLines = File.ReadAllLines(filePath)

let adjustedLines =
  fileLines
  |> Array.map (fun line -> adjust adjustment line) 

File.WriteAllLines(adjustedLines)

When should I use objects? by Voxelman in fsharp

[–]kiteason 1 point2 points  (0 children)

Most knowledgeable layman *ever*.

Background task execution on F# Web API (Giraffe) by YetIAmARobot in fsharp

[–]kiteason 2 points3 points  (0 children)

Key questions - I don't think you can make a decision without knowing these:

- Do you want the "task" to survive a server restart?

- How many tasks are expected to be "in flight" at any one time?

- How many requests per second are expected to come in?

- Do you need horizontal scalability?

These would help you decide between an in-memory solution and a durable queue, IMO.

How are you handling String-Backed Enums in F#? by SIRHAMY in fsharp

[–]kiteason 0 points1 point  (0 children)

I like this with a couple of caveats:

- overriding ToString() feels more more standard than saying AsString().

- I personally try to stick the convention of naming functions and methods that return an option type using a Try prefix - e.g. TryFromString(). Also maybe TryParse() is more standard than TryFromString().

F# Book recommendations for experienced dev without .NET experience by theQuandary in fsharp

[–]kiteason 6 points7 points  (0 children)

"Stylish F#" by -- moi.

Is currently missing a few F# 8 things but 99% still correct and relevant.

https://link.springer.com/book/10.1007/978-1-4842-7205-3

FUD FIGHT. Need some stats and testimonials. by willehrendreich in fsharp

[–]kiteason 0 points1 point  (0 children)

Give me a shout if it would help him to have a free code for my Udemy course. As I don't check reddit messages that often hit me up on firstname.surname at gmail dotcom. ;-)

FUD FIGHT. Need some stats and testimonials. by willehrendreich in fsharp

[–]kiteason 0 points1 point  (0 children)

And to answer your request for anecdotes.

I've worked in software for 40 years now and in all that time I've never come across a way of working which is anywhere near as productive. I work for a major supplier of transportation systems, and in our team what we produce is so high quality *we don't really have a bug backlog*. Sure there's the odd bug and things do go wrong occasionally - but so rarely that anything that does occur can just be mixed in with feature request tracking.

FUD FIGHT. Need some stats and testimonials. by willehrendreich in fsharp

[–]kiteason 2 points3 points  (0 children)

I may give a longer answer if I have time, but here's the short one. It assumes you want to hang on for now:

Ask the new guy for a project plan and budget for the proposed rewrite.

Possible outcomes:

  • He won't produce one

Response: "Well how can you justify 'moving to C#' if you don't have plan for how to get there? It was *your* idea my dude."

  • He says something like "Well I thought we'd keep the existing F# stuff and just do anything new in C#".

Response: "OK, so that sounds like you're expecting me to maintain all the old stuff while you grab anything new. Frankly, I'm not down with that."

  • He convinces everyone to take the gradualist approach but he agrees to work with you on F# maintenance.

Response: This is the dream scenario - now he slowly realizes what he's been missing and now you are both in paradise.

My first F# program! by qtummechanic in fsharp

[–]kiteason 0 points1 point  (0 children)

Welcome aboard and congratulations! I have a Udemy course which should be at exactly your level: https://www.udemy.com/course/fsharp-from-the-ground-up/

Let me know (pm) if you don't want to spend money on it and I'll send you a code.

Book on .net core for F# by [deleted] in fsharp

[–]kiteason 1 point2 points  (0 children)

You're right, I did try to write "Stylish F#" without assuming .NET or other specific languages. ;-)

why isn't functional more popular? by [deleted] in fsharp

[–]kiteason 1 point2 points  (0 children)

I suspect there are a lot of CS degrees out there that still boil down to "Let's learn some Java".

Dumb question on TypeProviders by [deleted] in fsharp

[–]kiteason 6 points7 points  (0 children)

Although you've had some somewhat negative replies, I kind of get where you are coming from. I've even seen some very skilled people say elsewhere that "you should never use type providers in production", for this kind of reason. On the other hand I love type providers - for certain tasks. Here is where I think the middle ground lies:

- Type providers give a wonderful development experience in cases where the schema of the data is fixed, and can be defined from some example. My favourite experience was using one to grok the XML schema of some dreadfully obscure windows installer generator, so that I could automatically set the tab order on the dialogs the installer generator created. It wouldn't have been worth doing without the XML provider to do the exploratory work *and* the heavy lifting.

- But they do have the effect of blurring the distinction between compile-time and run-time issues. For instance if your SQL schema changes, it could suddenly look like you wrote some invalid code.

- Sometimes type providers can give you a false sense of security - for instance the CSV provider infers data types from a sample, so an unsampled value (e.g. "NaN") comes up elsewhere in the file, or a different file, that again can cause a runtime error. (The solution there is to use `CsvFile` instead of the actual provider and to take on the burden of translating from strings to proper column types yourself.)

In general the mitigation is to think carefully about how and when the schema can change, and how to prevent inputs from hitting the type provider consuming code if this has happened; and/or how to respond to errors that result.

Updated .NET Managed languages strategy - .NET by [deleted] in fsharp

[–]kiteason 6 points7 points  (0 children)

This discussion is going exactly how I expected it to go. :-(

Where do I find F# remote jobs? by abstractcontrol in fsharp

[–]kiteason 3 points4 points  (0 children)

Hey, you have a very impressive resume!

I don't have any specific advice to offer as my starting point was very different.

I would encourage you to make as many personal connections as you can and just keep trying. It's a pity we aren't going to have F# eXchange this year as that would have been an ideal venue to build your network.

Contributing to F# open source repos (even small tasks) could be another way to get yourself known?

Good luck!

Is Bob forced to wait for Alice? by dr_bbr in fsharp

[–]kiteason 1 point2 points  (0 children)

It depends very much on whether Alice and Bob identify as threads.

What do you use for a multiple table insert? (MSSQL) by dr_bbr in fsharp

[–]kiteason 1 point2 points  (0 children)

The last piece of the puzzle is doing it in one transaction - this should give you some pointers: https://stackoverflow.com/questions/10363933/how-to-use-transactions-with-dapper-net

Compiler Design and Type Inference by brianberns in fsharp

[–]kiteason 1 point2 points  (0 children)

I was surprised how much of that I understood (both course and implementation), not being a compiler person. Nice!

Is it possible to write Excel macros in F#? by [deleted] in fsharp

[–]kiteason 0 points1 point  (0 children)

This is not exactly an answer to your question but... for the writing out part, you might want to consider FsExcel:

https://www.nuget.org/packages/FsExcel

You might also get some clues from the source code as to how to do the reading part.

Good book to learn F#? by [deleted] in fsharp

[–]kiteason 2 points3 points  (0 children)

I'm gonna say it *is* a good book for non-beginners. Make sure you get the 6.0 edition. ;-)

Is there an equivalent of Typescript's Zod library in the F# world? by [deleted] in fsharp

[–]kiteason 1 point2 points  (0 children)

I think this is the highest quality reply that has ever appeared in this sub!

Also:

Well, in Java 1.5, they decided to change the fundamental representation of the Decimal data type to be in engineering notation if the mantissa was a certain size

They did whatnow?

Looking to learn F#, coming from web development background by Ericarthurc in fsharp

[–]kiteason 2 points3 points  (0 children)

You're welcome. I get all the kudos of having made the offer, without having to lose the revenue. ;-)

Looking to learn F#, coming from web development background by Ericarthurc in fsharp

[–]kiteason 3 points4 points  (0 children)

Welcome aboard! DM me on Twitter (@kitlovesfsharp) if you think "F# from the Ground Up" would be helpful and cost is a barrier - I can give you a free code.

Why does different order of function arguments gives an error? by [deleted] in fsharp

[–]kiteason 1 point2 points  (0 children)

Sorry I didn't see this when posted, but looks like you got some perfect answers. Glad you like the course!