#BabelOfCode 2024
Week 11, Puzzle 17
Language: Idris
PREV WK: mastodon.social/@mcc/114582208…
NEXT WK: mastodon.social/@mcc/117661433…
PUZZLE TEXT: adventofcode.com/2024/day/17
Now getting extreme with "puzzles out of order". Here's the problem. The AOC author *really* likes puzzles involving 2D arrays. It makes sense. They're easy to visualize as either ASCII art or PNGs. They're a rich space for "simulations". But some languages are better at them than others.
So for Idris week, I pick the "build a CPU" puzzle.
mcc (@mcc@mastodon.social)
#BabelOfCode 2024 Week 10, Puzzle 11 Language: Textual Wasm Confidence level: Medium high PREV WEEK: https://mastodon.social/@mcc/114524697727786286 NEXT: https://mastodon.mcc (Mastodon.social)
This entry was edited (Sunday, November 22, 2026, 8:47 PM)
mcc
in reply to mcc • • •Idris is "Haskell, but more so". Haskell is "ML, but more so". I have always liked ML. I have never liked Haskell (although when I tried it again for this thread series, I enjoyed it more than I expected). I have always suspected I might like Idris more than Haskell. Maybe the awkward concepts in Haskell aren't *awkward* just *incomplete*. Maybe another language could complete them.
Conveniently, Idris installs itself through the Haskell package manager, which I already installed for week 7!
mcc
in reply to mcc • • •Inconveniently the Haskell package manager doesn't fricking work.
What… I don't understand what this very long error message is telling me. Do I need to upgrade Cabal? Do I need to downgrade Cabal? Is some existing package I have selected in a version incompatible with Idris? I can literally blow away my entire set of installed Haskell packages, I don't mind. Would that help? 🙁
EDIT: A six year old Google Groups comment reveals the secret is to pass cabal the flag "--allow-newer". Terrifying
mcc
in reply to mcc • • •Cont'd
- Passing --allow-newer fails *worse*—well, I turned the safety off
- I read the tutorial closer. It links a github
- The github is archived.
- I back ALL the way out. Instead of searching "idris tutorial" I go to the Idris home page. I then discover
- I have been looking at the Idris 1 tutorial. Idris 1 is discontinued. New thing is Idris 2.
- Idris has a totally different tutorial and is now deployed via Racket instead of Haskell (?!??)
- I have been, apparently, barking up a dead tree.
LR
in reply to mcc • • •dyssociative function
in reply to LR • • •@lritter yeah if you want to get started with idris, please ask for help, it will save you a lot of time.
i usually recommend github.com/stefan-hoeck/idris2… for installing idris 2. and the default backend is chez rather than racket.
GitHub - stefan-hoeck/idris2-pack
GitHubmcc
in reply to dyssociative function • • •Robin Adams
in reply to mcc • • •Andre Videla
in reply to mcc • • •@dysfun @lritter We have a zulip! idris-lang.zulipchat.com/ Let me know if you have any questions as well. The language is much less polished than I want but we're working on it to make it better every day. All feedback is welcome
Edit: I'm working on tech debt on the idris2's LSP implementation as we speak!
Edit2: I'm UTC+0 (+1 soon)
Public view of Idris Community | Zulip team chat
Zulipdyssociative function
in reply to Andre Videla • • •@Andrev @lritter
lol, i'm a huge idris fan and you couldn't handle all my feedback, let alone anyone else's 😂
Andre Videla
in reply to dyssociative function • • •dyssociative function
in reply to Andre Videla • • •@Andrev no, it's a wonderful property, in theory.
but there's so much that would need to be improved to make it something anyone less nerdy than us would use, and i don't think it's realistic to think it will ever get there. so i worry about what extended honest feedback would do for your mental health.
Andre Videla
in reply to dyssociative function • • •Raven667
in reply to mcc • • •I see the levels on the frustration machine are nominal
That sucks
ShadSterling
in reply to mcc • • •“I have been, apparently, barking up a dead tree”
moood
mcc
in reply to mcc • • •So.
I install Racket. Wow! Racket takes up a lot of space! I guess I'll need this for week 14 anyway.
I install "pack", Idris's dedicated package manager. I guess I don't get to be happy Idris uses an existing package manager anymore. Installation for the Idris package manager is "curl to bash". The bash script clones a git repo. There is weeping and gnashing of teeth. There is no way I will remember to uninstall this thing or remove it from my bashrc files when this project's done. Whatever.
Stefan Prandl
in reply to mcc • • •mcc
in reply to Stefan Prandl • • •Zoe : Void -> a
in reply to mcc • • •mcc
in reply to Zoe : Void -> a • • •Zoe : Void -> a
in reply to mcc • • •mcc
in reply to Zoe : Void -> a • • •Zoe : Void -> a
in reply to mcc • • •mcc
in reply to mcc • • •Anyway! Idris! I'm in!
Idris is a "dependent types" language. "Dependent types" are the thing your favorite language doesn't have that prevents you from having that feature you wished it had but it doesn't. A running gag in Rust is every desirable but missing feature would be possible with dependent types. DT means a type can contain a value, or do ops on values, for example a function that adds an array of length N to an array of length M and produces an array M+N. Like Ada, but… … … better?
mcc
in reply to mcc • • •For some reason Idris has two tutorials.
idris2.readthedocs.io/en/lates…
idris-community.github.io/idri…
Reading how they describe their types, I wonder if the CPU emulator puzzle was the wrong choice for this language. Something with arrays might've better exercised Idris' capabilities?
First thing that catches my eye: it has an "infix" sugar like ML. But then they say:
"Functions, data constructors, and type constructors may all be given infix operators as names."
TYPE CONSTRUCTORS MAY BE INFIX
HECK YES
The Idris 2 Programming Langauge - Idris 2 Tutorial
idris-community.github.ioCassandra is still spooky
in reply to mcc • • •Idris Failba
in reply to mcc • • •Klara in the hidden land
in reply to mcc • • •If I remember anything from grad school it's that any nontrivial problem presents some interesting use cases for dependent types.
But whether this is a blessing or a curse in your case I can't say.
mcc
in reply to mcc • • •Unsorted thoughts
"Holes are useful." is a funny sentence to see in a manual
"where" and "let" seem redundant
> Nested record fields can be accessed using the dot notation:
>
> x.a.b.c
> map (.a.b.c) xs
…Haha heck nice, that was the feature I was proudest of in Emily
"multiplicity 0" (calculated/erased at compile time) and "multiplicity 1" (linear typing) sound like things I VERY MUCH want in a programming language, though the ergonomics around it are a little alien to me, a C/Rust girl
mcc
in reply to mcc • • •Okay important question
I have a vague sense Haskell has "monads" and Idris has "applicatives". Idris in fact seems to have both— idris2.readthedocs.io/en/lates…
If I say "do" I've made a monad and if I say "[| … |]" (ugh, ocaml at its worst) that's an applicative. Difference isn't clear. If I just write monads and ignore [||] in my learning-Idris program am I Missing Out?
I still don't know what an Effect is. I thought it was the Effect Monad but the Idris manual talks like applicatives are Effects.
Interfaces — Idris 2.0 Documentation
idris2.readthedocs.ioprozacchiwawa
in reply to mcc • • •cassie
in reply to mcc • • •mcc
in reply to cassie • • •cassie
in reply to mcc • • •mcc reshared this.
Caden
in reply to cassie • • •cassie
in reply to Caden • • •@tarix29 @prozacchiwawa oh right I forgot that eventually got fixed like a decade ago: wiki.haskell.org/index.php?tit…
They didn’t fix the duplicated incompatible names though, so it’s still idiomatic to use different names for the same operation depending on what typeclass you’re working with. In Idris all the operations just get one name.
Functor-Applicative-Monad Proposal - HaskellWiki
wiki.haskell.orgCaden
in reply to cassie • • •cassie
in reply to cassie • • •mcc
in reply to mcc • • •Okay so the important things seem to be this comment
social.treehouse.systems/@dysf…
the second screenshot (the terminal shot) attached to this post
and this comment
mastodon.social/@porglezomp/11…
I still don't understand it, but I think I'm closer to understanding it than I have been ever in the last 25 years. Just gotta think about those type signatures. And in the meantime I don't *have* to understand it, I can just use do notation and worry later about which Math Things my code corresponds to.
dyssociative function
2026-10-14 19:57:19
Cassandra is still spooky reshared this.
Michelle Hughes
in reply to mcc • • •mcc
in reply to Michelle Hughes • • •Michelle Hughes
in reply to mcc • • •Jim Rootham
in reply to Michelle Hughes • • •Michelle Hughes
in reply to Jim Rootham • • •Yeah. That's why I tried it on a logic puzzle game. That's exactly the sort of thing that logic programming is for.
d@nny disc@
in reply to Michelle Hughes • • •d@nny disc@
in reply to d@nny disc@ • • •Fait partie des meubles
in reply to mcc • • •mcc
in reply to mcc • • •Among the things not mentioned in either Idris tutorial
- What file extension is used for Idris files? (it's .idr)
- How do you execute an idris file?
Running idris2 puts you at a REPL. Running "idris2 src/puzzle.idr" churns a long time, creates a series of utterly baffling files in a build/ subdirectory, then drops you at the same repl. "-c" does this then quits; but it still does nothing useful.
One tutorial implies "pack -o hello exec src/puzzle.idr" will do something; this hangs forever
mcc
in reply to mcc • • •I understand true LISP heads are comfortable just spending all their time in a REPL forever. I am not a true LISP head. I'm an ocaml poser.
I *think* the mysterious "pack" command, while hanging, created in the mysterious "build" subdirectory a "hello.rkt" file that wouldn't have been there otherwise. I remember someone saying idris works by transpiling itself to a "backend" lang, so maybe I'm supposed to figure out the non-hanging args to "pack", transpile, then execute the rkt file in racket.
mcc
in reply to mcc • • •*Rubbing eyes* okay, so
idris2's command line --help lists a "-o <file>" flag, which "specifies output file". Output file for what? Apparently this actually means "build an executable, put it in ./build/exec [path non-negotiable], and name it <file>".
I run this. I run it in `time`. It does create a runnable Linux executable.
It takes it one minute and fifty-three seconds to compile the program:
main : IO ()
main = putStrLn "Help"
During which time I sincerely could not tell if it had hung
mcc
in reply to mcc • • •So after a brief conversation with Idris2 maintainers
- Idris can run on top of either "Racket" or "Chez". I went with Racket because I thought it was the fast one. This is no longer true. The maintainers expect Chez to be a little faster. In fact it's hundreds of times faster. This surprises the maintainers.
- Additionally, in Debian, Chez takes up 10% the disk space of Racket.
After what I'd consider a somewhat unfriendly uninstall procedure, I re-install idris2, atop Chez.
It doesn't work
mcc
in reply to mcc • • •After some poking, it turns out that installing Idris2 in Racket mode, then uninstalling with the given instructions, then re-installing in Chez mode, leaves the system in an inconsistent state where it sometimes uses Racket and sometimes doesn't work at all. I need to stress I have various community members and maintainers in my mentions trying to help me and they're being very nice. They give me hand-surgery to perform on a TOML file. It ixes it. Compiling takes 1.4s instead of over 2 minutes.
mcc
in reply to mcc • • •Furthermore, it appears that in addition to the two tutorials I mention above, the ones linked from the regular Idris website, there is a third, secret tutorial, and this one explains how to actually execute a piece of code, explains why readline isn't working right in the idris2 repl, etc. codeberg.org/jjl/tutorials/src…
I guess I can move on now. Hopefully there aren't more nasty surprises lurking in my toml configuration file (presumably lying in wait to blow up if I attempt to configure an LSP).
tutorials/00-setup.md at main
Codeberg.orgmcc
in reply to mcc • • •So Sublime Text doesn't have an Idris LSP package-- only an Idris syntax highlighting package.
But it turns out if I `pack install-app idris2-lsp, then in Sublime go to Package Settings -> LSP -> Server Configurations
{
"idris2-lsp": {
"enabled": true,
"command": ["/home/mcc/.local/bin/idris2-lsp"], // Update the PATH
"selector": "source.idris"
}
}
It just like… magically works. I have type-on-hover now. As long as I create a .lidr file with idris2 --init.
mcc
in reply to mcc • • •27 hours after beginning this thread, I successfully write my first line of Idris code. (It's opts <- getArgs). Now I just need to figure out how to get an item out of a list.
There's a better looking options parser in the standard "contrib" library, but I can't figure out how to get it out. I decide to dip a toe in the idris Zulip.
idris-lang.zulipchat.com/#narr…
Among the deficiencies in the tutorials: They describe how to find third party libraries, but not how/where the stdlib is used/documented…
Public view of Idris Community | Zulip team chat
Zulipmcc
in reply to mcc • • •Tried to write my second line of Idris. Disaster.
It's highlighting "=>" and giving the error "Expected '=>'". Don't know how to proceed.
Part of the problem is Idris has elaborately documented its upgrades from Haskell, but the tutorials kinda handwave the basic stuff. In ML I'd expect to deconstruct a one-element list like [x] or like x::nil. In Idris I… I don't know. Maybe if I sleep and reread all the docs.
Also, I'm missing how I, inside of a do, "abort the do block/program with error"
∴ esoterik ∴
in reply to mcc • • •mcc
in reply to ∴ esoterik ∴ • • •@d6 hm. it doesn't like that either and for the same reason.
is the real problem that getArgs is inside an io monad and i have to unwrap it?
actually i think this must be a problem with my actual syntax because if I change "getArgs" to "getArg" I get the same error. Implying the compiler is bailing out so early it isn't checking names.
Amélia Liao 🍊😈
in reply to mcc • • •arg <- x, that's not an expression.mcc
in reply to Amélia Liao 🍊😈 • • •rntz
in reply to mcc • • •I don't understand why that is the error message and I don't know what the "exit program" function is. However: your pattern is fine; idris understands `[x]` as a pattern in `case`. But you do need to bind `getArgs` outside the `case` (b/c getArgs is in the IO monad), eg. this works:
import System
main : IO ()
main = do
args <- getArgs
case args of
[x] => printLn x
_ => putStrLn "nope"
rntz
in reply to rntz • • •looks like exitWith or die will exit: idris-lang.org/Idris2/base/doc…
eg this will print its "first" command-line argument (the 1st element of getArgs is the command itself, so the 1st "argument" is actually the 2nd element).
main : IO ()
main = do
args <- getArgs
arg <- case args of
[_, x] => pure x
_ => die "wrong number of arguments"
putStrLn arg
System
idris-lang.orgmcc
in reply to rntz • • •rntz
in reply to mcc • • •Without pure, the two case-branches have different types. `x` is a String, but `die "..."` is an IO computation. `pure x` puts x into the IO monad, so both branches can have the same type, IO String.
for comparison, consider an expression like
if test() then 2 else "wub"
this seems ill-typed, because 2 and "wub" have different types. in Idris, IO-computations have different type from non-IO things, and a String is not automatically convertible to an IO String.
Mark W. Gabby-Li
in reply to mcc • • •The Orange Theme
in reply to mcc • • •mcc
in reply to The Orange Theme • • •mcc
in reply to mcc • • •Okay making some progress with help from Mastodonites but
*gestures at below screenshots*
Why
Dieu
in reply to mcc • • •mcc
in reply to Dieu • • •cholling
in reply to mcc • • •mcc
in reply to cholling • • •miniBill (Leonardo)
in reply to mcc • • •Dieu
in reply to mcc • • •Dieu
in reply to Dieu • • •cassie
in reply to mcc • • •You can freely move around expression that you write with `let`, you cannot freely move around expressions that you write with `<-` because that is doing a monad bind. Notably in a bind, the type of the variable is different from the type of the expression you’re binding from.
`do x <- getArgs; f x` is syntax sugar for `getArgs >>= \x -> f x`, which maybe helps you carefully work through all the types manually?
cassie
in reply to cassie • • •mcc
in reply to cassie • • •cassie
in reply to mcc • • •Rachel Barker
in reply to mcc • • •To make a (very rough!) analogy to an imperative language, `args <- getArgs` is like calling a function, `getArgs` by itself is like naming the function itself.
So the first example is like writing
```rust
let args = getArgs();
match args {
...
}
```
While the second example is like writing
```rust
match getArgs {
...
}
```
which fails because you can't pattern-match on a function
mcc
in reply to mcc • • •I am struggling with making sense of this language's standard library.
The attached code works. It takes a filepath as argument and prints the contents.
But
- If instead of System.File.ReadWrite I use Control.App.FileIO, nine kinds of hell erupt
- I can't figure out how to turn the FileError (Left x)idris-lang.org/Idris2/base/doc… into… ANYTHING. I can't get that "Show FileError" to do anything in the repl. "import" in the repl fails
- In general, I can't search prelude/base for a symbol by name?
System.File.Error
idris-lang.orgmcc
in reply to mcc • • •Moreover, I don't want to put the file contents into a string. I want to parse them in a very simple way— verify text "Register A:" at start of line one, parse comma-separated list, move on to line two etc. I don't know how to get "here's a list of string ops" "here's a list of file ops". I find this idris-community.github.io/idri… it's explaining concepts of applicatives and I want to know what operations exist for simple parsing of strings. I don't know what "go" does or where to look it up.
Working With Files - Idris 2 Tutorial
idris-community.github.iocassie
in reply to mcc • • •mcc
in reply to cassie • • •Amélia Liao 🍊😈
in reply to mcc • • •gois the name of the function defined in thatwhereclausemcc
in reply to Amélia Liao 🍊😈 • • •Andre Videla
in reply to mcc • • •btw in case that helps. I think you've got the right idea but you're tripping over syntax and the tutorial is going a bit too fast
mcc
in reply to Andre Videla • • •Andre Videla
in reply to Andre Videla • • •careful, if you write
length args - 1this won't work becauselengthreturns aNatwhich doesn't support a-operator because it doesn't have values below0because it's a "natural number"dyssociative function
in reply to Andre Videla • • •minusfunction which just stops at 0)mcc
in reply to mcc • • •OK so this is great but also, it speaks to what I perceive as a "missing low-end" in the Idris docs— like, if I want a high-end library for doing command-line argument parsing I can find that in seconds in the well-curated third-party libraries list and install it via Pack, but if I want to know the name, package and type signature of the "getArgs" function in the standard library this is shockingly much harder.
Maybe :doc will help some now that I know about it.
mastodon.social/@dysfun@treeho…
Mastodon
mastodon.socialdyssociative function
2026-10-15 21:58:24
mcc
in reply to mcc • • •Oh no oh no oh no. it's my least favorite friend from OCaml— Spooky Type Action at a Distance
mcc
in reply to mcc • • •mcc
in reply to mcc • • •Christina Richards
in reply to mcc • • •mcc reshared this.
Christina Richards
in reply to Christina Richards • • •Tabby
in reply to Christina Richards • • •Christina Richards
in reply to Tabby • • •Tabby
in reply to Christina Richards • • •Christina Richards
in reply to Tabby • • •qurlyjoe
in reply to Christina Richards • • •Kinky.
Briala
in reply to mcc • • •mcc
in reply to mcc • • •…did this compiler just *apologize* to me
chris martens
in reply to mcc • • •mcc
in reply to mcc • • •Briala
in reply to mcc • • •mcc
in reply to mcc • • •Okay so I *think* I managed to fix the "monad" errors in this, and I'm proud of that
gist.github.com/mcclure/8c6baa…
But I am utterly defeated by the error "Mismatch between: AsList (strCons ?_ ?str) and List1 String." (a later error gives this as "Mismatch between: List ?a and List1 String."). I thought ? meant there was a hole. But I didn't write any holes
Hey is there a builtin "dispose" function in Idris. Like _ -> () if I want to end my do block with a value but I'm not ready to do with anything
puzzle.idr
Gistmcc
in reply to mcc • • •What if
You sent your program to the compiler
And it said
?_ ?
May likes Toronto
in reply to mcc • • •The Orange Theme
in reply to mcc • • •mcc
in reply to The Orange Theme • • •Gabe
in reply to mcc • • •Neia masks
in reply to mcc • • •muddle 🥣
in reply to mcc • • •I'd probably try ';'
(edit: but then, I've probably got repl brain and thinking more in terms of Prolog...)
njplschy
in reply to mcc • • •the middle one looks the most sensible since you're working with Lists and not any of this aslist or stream stuff
I looked up the type of split and it returns a List1 a which has constructor (::😀 : a -> List a -> List1a, so in that case expression you would watch to match on the pattern (_ ::: [_, i_string])
mcc
in reply to njplschy • • •njplschy
in reply to mcc • • •mcc
in reply to njplschy • • •@ionchy
Error: While processing right hand side of main. While processing right hand
side of main,interpret_register. Undefined name :::.
src.puzzle:26:7--26:10
24 | let words = split (== ' ') line in -- Split on spaces, throw away first two cells
25 | case words of
26 | _ ::: [_, i_string] => case parseInteger i_string of
^^^
Did you mean: ::?
And no, adding parens does nothing
njplschy
in reply to mcc • • •import public Data.List1maybe?mcc
in reply to njplschy • • •njplschy
in reply to mcc • • •Farbs
in reply to mcc • • •mcc
in reply to Farbs • • •mcc
in reply to mcc • • •mcc reshared this.
Farbs
in reply to mcc • • •mcc
in reply to Farbs • • •Ben Zanin
in reply to mcc • • •*tips hat* m'nad
edit: I regretted this instantly
Timo the timo
in reply to mcc • • •airakose
in reply to Farbs • • •@Farbs it's one of those vocab terms that once you learn what it means, it's like... "oh... I've been doing that this whole time"
Like memoization (rt had to search for this term by definition bc I could not for the life of me remember what it was)
(at least that's how it goes for me)
Crazazy @ my computer c:
in reply to mcc • • •Ok sothe vague error has mostly to do with one thing, and that is overloaded strings. Essentially the first error is telling you "I have trouble deciding if this is something looking like a string, or a List1 String, either way this has the wrong type". However, Idris doesn't know *what* kind of string you're using, so you get *that*
The main problem is split returns a List1, not a List, so you can't pattern match on it like a List. Instead of "[_, _, i_string]", try "_ ::: [_, i_string]"
Crazazy @ my computer c:
in reply to Crazazy @ my computer c: • • •mcc
in reply to mcc • • •*Rubbing eyes* okay. Okay.
So what I wanted is a List String. "split", the string function, returns a List1 String. I assumed the 1 was "noise". Using this language, I find a lot of "noise" in the messages and docs.
No, it was very important.
So to construct or deconstruct a list in a post-LISP FP language, you use :: , right? Everyone knows that. Right before I went to bed last night, I got a message saying I needed to use ::: , not :: . I literally assumed this was wrong. No, It was right.
mcc
in reply to mcc • • •What I *should* have done, when the split doc said List1, is look up what that was. I mean, I did, and it said a List1 is just a List with at least one element. That sounded normal to me. Idris is all about the dependent types thing, right? So logically this should just be a List with some constraint on it. I assumed it would work like a List.
No, it's different. To interact with it you have to import Data.List1, then use ::: instead of :: .The [a,b] sugar will not work.
I… hm. Hrm. Hmrmrmhf
mcc
in reply to mcc • • •One thing that concerns me: What if, for some reason I can't currently guess, I needed a List which is dependently typed to have at least 26 elements? Would I define a List26, and assign it :::: , and hope it doesn't conflict with someone else's List4 which also defined a :::: ? Starts feeling weird
Anyway, now onto the next problem: DYING IS A SIDE EFFECT. WHAT DO YOU MEAN DYING IS A SIDE EFFECT. LIKE OK IT IS BUT I SHOULD BE ABLE TO DIE ANYTIME I WANT. I'M NOT ALLOWED TO DIE WITHOUT A MONAD??
Jonathan Lamothe
in reply to mcc • •error.Luna Dragofelis ΘΔ🏳️⚧️🐱& likes this.
mcc
in reply to Jonathan Lamothe • • •@me Is there?
Searching:
idris2docs.sinyax.net/
The only thing I think I find is idris2docs.sinyax.net/data/idr… , which is based on idris2docs.sinyax.net/data/bas… .
App means applicatives are in effect, right? I'm in the … HasErr… applicative? Which OK, I think means I don't need a monad. But does that mean I have to declare all my functions all thew way up as HasErr? Will the IO monad and the HasErr applicative fight when they come into contact?
Idris2 Docs
idris2docs.sinyax.netLuna Dragofelis ΘΔ🏳️⚧️🐱& likes this.
mcc reshared this.
Jonathan Lamothe
in reply to mcc • •die :: String -> IO a.Luna Dragofelis ΘΔ🏳️⚧️🐱& likes this.
Crazazy @ my computer c:
in reply to mcc • • •Amélia Liao 🍊😈
in reply to Jonathan Lamothe • • •Builtin
idris2docs.sinyax.netmcc
in reply to Amélia Liao 🍊😈 • • •Amélia Liao 🍊😈
in reply to mcc • • •Dieu
in reply to mcc • • •cassie
in reply to mcc • • •njplschy
in reply to mcc • • •Either Int String, whereLeft nis your good result andRight "I die"is your bad result (or maybe the convention is the reverse? idr)however this means that every time you use a function that returns an
Eitheryou need to case on the result and propagate the errorbut you can do this automatically... by treating it as a monad lol
mcc
in reply to njplschy • • •njplschy
in reply to njplschy • • •mcc
in reply to njplschy • • •Amélia Liao 🍊😈
in reply to njplschy • • •Philippa Cowderoy
in reply to Amélia Liao 🍊😈 • • •Crazazy @ my computer c:
in reply to mcc • • •mcc
in reply to mcc • • •So my understanding of haskell "monads" is that they're really just very fancy syntactic sugar for wrapping each line of code in some kind of transformation. Usually the monad is "IO" because the transformation is a magic "wait for external input".
It seems like I ought to be able to use a monad to do wrapping similar to Rust Result<>?, and not have to go all the way to IO, and still have a pure function. Someone said Either is a monad.
Someone says, "you can use error"—EDIT: No,that's Haskell
mcc
2026-10-16 16:24:49
prozacchiwawa reshared this.
erincandescent ⎔
in reply to mcc • • •mcc
in reply to erincandescent ⎔ • • •erincandescent ⎔
in reply to mcc • • •it's not so much that you can't really express them in Rust, it's that you can't be generic over them.
A monad is conceptually just a collection Foo<T> that matches the pattern of Option<T>::and_then, Vec<T>::flat_map, et al.
Haskell calls this method "bind". "Do notation" is just syntactic sugar for wrapping an expression in this method.
Rust can't express a Monad trait (as would be required for Do notation) because you can't express a trait that's generic over type parameters
mcc
in reply to erincandescent ⎔ • • •soc
in reply to mcc • • •@erincandescent If you go into that direction, it might make more sense to adopt Algol-style unions:
Then you'd get to share variants between enums for free, on top of a generally better design compared to "Rust" enums.
rntz
in reply to mcc • • •error is an escape mechanism in Haskell that lets you throw an error even in pure (non-monadic) code. It would be convenient for what you are doing but it is frowned upon as “the wrong way to do things” (and for large programs and libraries it does indeed have problems) compared to learning to do everything with monads.
I don’t think Idris has error. It might have some other escape hatch like it though.
mcc
in reply to rntz • • •rntz
in reply to mcc • • •almost certainly it’s also a Monad? on phone so it’s hard for me to check rn…
Every Monad is an Applicative but not always vice-versa but it would be weird if Control.App.Error wasn’t a monad.
EDIT: Nope I think I’m wrong here. Not even sure that Control.App is about applicatives.
EDIT2: edit was wrong. Control.App.App is a monad (Control.App.Error isn't). but also it seems kinda complicated. I am not familiar with this part of Idris and it doesn't look like anything I know from Haskell.
dyssociative function
in reply to rntz • • •@rntz no, you're not wrong, App is a monad idris-lang.org/Idris2/base/doc…
Control.App.Error is an alias for Type.
Control.App
idris-lang.orgrntz
in reply to rntz • • •dyssociative function
in reply to rntz • • •idris2_crashiirc and you have to top it up withassert_totalto make it not fail coverage checks.mcc
in reply to mcc • • •Okay. So. The consensus from Idris users is to manually bubble the errors up using Either, like I'm a barbaric Rust user or something. I hit several problems.
gist.github.com/mcclure/a7498d…
1. Either and Maybe are monads. I've been told this since 2010. That implies I should be able to "do" them. I should have some way of rigging stuff so that, when a operation fails, "aborting" it like ? in Rust. Instead like chaining case statements like I'm a barbaric Ocaml user. Am I missing something?
(CONT'D)
puzzle2.idr
Gistmcc
in reply to mcc • • •2. It reeeeeallly bothers me that I'm using Either for error handling because it is not semantic. I'd like success to be Ok and failure to be Err. If I kept using Idris, how hard would it be for me to make an interchangeable Result version of Either with different names?
3. My code used a `map`. Therefore in order to bubble up errors, I need a way to "terminate" a map early. It turns out this exists and it's called "traverse". It furthermore turns out TRAVERSE TREATS LEFT AS ERROR
(CONT'D)
prozacchiwawa reshared this.
mcc
in reply to mcc • • •AND RIGHT AS SUCCESS. SO ONE (1) FUNCTION SWAPS FAILURE/SUCCESS BETWEEN LEFT AND RIGHT. I'm not asking for help here I'm just annoyed
4. Here's the point I actually need help: As you can see from "z_error.txt" in the above-linked gist, traverse can't operate on a List1.
…what?!
…what's even the point of higher-order functions over interfaces¹ then 🙁 🙁 🙁
I'm stuck. What should I do here? Write a function to convert List1 to List? List1 *is* a superset of List…
¹ "Typeclasses"
Cara
in reply to mcc • • •mcc
in reply to mcc • • •Answers to above questions
2. It turns out in Idris Left semantically means `Error` and Right semantically means `Ok`. Every standard library function follows this convention.
3. See 2
1. Just `do` when the return type is Either and any <- that attempts to assign Left auto-aborts. Like every line has an implicit ?. Awkward compared to ?, but better than nothing.
4. The actual error was ") in wrong place"— hard for any compiler to explain. Correct ) gives better error. Also: Data.List1.forget
cassie
in reply to mcc • • •mcc
in reply to mcc • • •_Έλλεν Εμίλια Ά. Arson Τζαϊλου
in reply to mcc • • •mcc
in reply to _Έλλεν Εμίλια Ά. Arson Τζαϊλου • • •@fogti One output I'm getting from this conversation is that Rust has *exactly* two monads, Option and Result. Of these, Option is right-wing
doc.rust-lang.org/std/option/e…
and Result is left-wing
doc.rust-lang.org/std/result/e…
This only affirms my position that Option was a mistake and should be purged from the language in favor of Result<T, ()>.
Option in std::option - Rust
doc.rust-lang.org_Έλλεν Εμίλια Ά. Arson Τζαϊλου
in reply to mcc • • •mcc
in reply to _Έλλεν Εμίλια Ά. Arson Τζαϊλου • • •_Έλλεν Εμίλια Ά. Arson Τζαϊλου
in reply to mcc • • •mcc
in reply to mcc • • •Idris question
Does this language have a "map_left" or "map_right". Like Rust map/map_err ( idris2docs.sinyax.net/data/bas… ). I want to do a transformation on a Either, but I want to apply the transformation iff it is Right. I think I could write this myself if I had the mastery required to do… the things I'm already failing at. I notice there's an "eitherMapFusion" idris2docs.sinyax.net/data/bas… with no human-readable documentation and a baffling type. idris2docs.sinyax.net/data/bas…
Data.Either
idris2docs.sinyax.netmcc
in reply to mcc • • •adsfkjdsglkjfdgljag
github.com/mcclure/aoc2024/blo…
After *three* days, I have written a 65-line program that parses a very simple text file in a very simple way in Idris, which is the *prerequisite* to *starting* the puzzle I was hoping to finish within the week. And I was only able to achieve this much through massive personalized help. I will now time myself trying to write an equivalent program in Perl:
aoc2024/17-01-cpu/src/puzzle.idr at d15c57397feea3bcdec11182c61dd00610181bc4 · mcclure/aoc2024
GitHubmcc
in reply to mcc • • •perl -e 'open(FH, $ARGV[0]) or die "No file"; ($a,$b,$c) = map {(chomp && scalar(/^[^ ]+ [^ ]+ (\d+)/ or die "Invalid register: $_"), $1)[1]} (scalar <FH>, scalar <FH>, scalar <FH>); <FH>; $program = <FH>; chomp $program; @program = split(/,/,$program); undef $program; close(FH); print "$a, $b, $c, program length " . +@program . "\n"' data/sample-4,6,3,5,6,3,5,2,1,0.txt
That took 12 minutes. 3 minutes to write the program and 8 minutes to debug it (It didn't work because I forgot "scalar".)
mcc
in reply to mcc • • •Krzysztof Sakrejda 🏳️⚧️ 🏴☠
in reply to mcc • • •mcc
in reply to Krzysztof Sakrejda 🏳️⚧️ 🏴☠ • • •Krzysztof Sakrejda 🏳️⚧️ 🏴☠
in reply to mcc • • •mcc
in reply to mcc • • •Hey question, does Idris have an equivalent of Ocaml |>
(I think this was "@@" in SML/NJ? And possibly $ in Haskell?)
EDIT: Yes… ha ha ha… yes! social.treehouse.systems/@dysf…
EDIT 2: In all the programming languages we write myself I just use ":" for this. It's that important to me. Nobody else I talk to ever seems to think this is good syntax
EDIT 3: Wait it isn't working
EDIT 4: Oh wait I asked the wrong question to start with. It's <| not |>
dyssociative function
2026-10-17 16:59:50
mcc
in reply to mcc • • •Haha what
idris2docs.sinyax.net/data/pre…
I'm not sure whether I understand it, but I love it
Prelude.Basics
idris2docs.sinyax.netmcc
in reply to mcc • • •You know you're using a functional programming language when you read through a module documentation containing about fifty functions trying to find the one that lets you look up a list member by index, and do not find it
idris2docs.sinyax.net/data/bas…
(I found two functions for getting the list index given a value, but did not find the function for getting a value given a list index. Not sure if my eyes glazed past it or if it's somewhere surprising in the Prelude)
EDIT: I think it's "index"
Data.List
idris2docs.sinyax.netChris Ford
in reply to mcc • • •mcc
in reply to mcc • • •Was trying to figure out how you destructure a record type in Idris and the answer turned out to be that you use *the constructor function* on the left hand side of a =. I am both impressed and frightened.
(…because it seems to imply this language has reversible computations when it doesn't quite, this is just a pinch of sugar.)
Pete Alex Harris🦡🕸️🌲/∞🪐∫
in reply to mcc • • •Fallible
in reply to mcc • • •mcc
in reply to Fallible • • •mcc
in reply to mcc • • •Update NOPE I did not in fact find the "index into a list" function. Because the index into a list function only exists if you can provide a proof that the index is less than the length of the list. Wait, but I don't know the length of the list? I was hoping the standard library would take care of that for me.
Experimentally, I try calling the inBounds function. It… something weird happens. It returns a "dec". Frustratingly, one of the types that isn't linked to its definition in the docs (1/2)
_Έλλεν Εμίλια Ά. Arson Τζαϊλου
in reply to mcc • • •mcc
in reply to _Έλλεν Εμίλια Ά. Arson Τζαϊλου • • •@fogti natToFin returns a Dec. but if I knew what to do with a Dec I could use inBounds mastodon.social/@mcc/117457579…
mcc
2026-10-17 18:07:03
_Έλλεν Εμίλια Ά. Arson Τζαϊλου
in reply to mcc • • •idris2docs.sinyax.net/data/bas…
no?
Data.Fin
idris2docs.sinyax.netmcc
in reply to mcc • • •But per :doc it appears to be a predicate function. I *think* I don't call inBounds, I think I somehow *define* inBounds.
I think my options are:
1. Ignore "index"; write my own index that manually skims the list & returns an Either
2. Convert my list to a Vector, somehow, with its length as a generic parameter, somehow, and then when reading from the list test if my index (input from file; out of my control) is less than that generic-parameter length.
2 sounds better, but harder *_*
(2/2)
Amélia Liao 🍊😈
in reply to mcc • • •inBoundsto split on whether the index is in the list, in which case you can useindex, or not in the list, in which case you can throw an error or something because you're inIOmcc
in reply to Amélia Liao 🍊😈 • • •@amy I have two tutorials open and neither appear to explain indexing into a list. What would you recommend I read if I need to understand what to do with a Dec ? Because I tried what you said with an "if" and it did not work.
files.mastodon.social/media_at…
Zoe : Void -> a
in reply to mcc • • •Prelude.Types
idris-lang.orgmcc
in reply to Zoe : Void -> a • • •Amélia Liao 🍊😈
in reply to mcc • • •Zoe : Void -> a
in reply to mcc • • •mcc
in reply to mcc • • •@zmz @amy
step : Cpu -> IO Cpu
step cpu =
let (NewCpu ip reg prog) = cpu in
case inBounds (ip+1) prog of
Yes =>
^^^ error here ^^^
let opcode = index ip prog in
let operand = index (ip+1) prog in
putStrLn (show opcode)
No =>
die "Nope"
Error: When unifying:
?prop -> Dec ?prop
and:
Dec (InBounds (plus ?_ 1) ?_)
Mismatch between: ?prop -> Dec ?prop and Dec (InBounds (plus ?_ 1) ?_).
I do not understand a single error message in this language 🙁
Zoe : Void -> a
in reply to mcc • • •Amélia Liao 🍊😈
in reply to mcc • • •YesandNohave an argument each.mcc
in reply to Amélia Liao 🍊😈 • • •okay. I see now. I was misreading the doc. Sorry, my head is swimming at this point and I'm missing obvious things.
The argument is given as a "Prop". Is this a value which means anything at runtime or is it like… I guess what I'd call a "phantom" in another language? Is there a reason to do anything other than _ it
EDIT: functional.cafe/@prozacchiwawa… seems to imply it's a phantom
prozacchiwawa
2026-10-17 18:16:07
Amélia Liao 🍊😈
in reply to mcc • • •propis just the name of the parameter toDec. It could be an arbitrary type, e.g.the (Dec Nat) (Yes 123); here, you are decidingInBounds (ip + 1) prog. Ideally the auto parameter toindexwill pick it up automatically, in which case it can be_, but otherwise you might need to give it explicitly. You don't have anything to contradict theNocase, so that can be ignored.Amélia Liao 🍊😈
in reply to Amélia Liao 🍊😈 • • •prozacchiwawa
in reply to Zoe : Void -> a • • •@zmz @amy
it can be difficult to understand how to handle the No case. If it's Decidable on something that yields bool, you can use this to invert No
idris-lang.org/Idris2/base/sou…
Data.Bool
idris-lang.orgmcc
in reply to prozacchiwawa • • •prozacchiwawa
in reply to mcc • • •@zmz @amy
No means: at the type level the thing you asked for couldn't be proven, so here's a function yielding Void that you can use with absurd or impossible to complete the proof.
mcc
in reply to prozacchiwawa • • •@prozacchiwawa @zmz @amy I see.
In my case, this is a legitimate error at runtime. I take input from a file which contains a list of numbers as well as indices into numbers. I can't know if an index is wrong at type time (unless I convert the list of numbers to a Vec, which I will probably try in the next step).
mastodon.social/@mcc/117457617…
mcc
2026-10-17 18:16:47
Amélia Liao 🍊😈
in reply to prozacchiwawa • • •@prozacchiwawa @zmz i mean assuming the index is an input you can't really do better than
Crazazy @ my computer c:
in reply to mcc • • •mcc
in reply to mcc • • •A proof that the natural (ip+1) is in bounds for array a is not a proof that the natural (ip) is in bounds for array a.
🙁
🙁
🙁 🙁 🙁
EDIT: [sad rageface ok face] ok tiny.tilde.website/@crazazy/11…
Crazazy @ my computer c:
2026-10-17 20:05:14
prozacchiwawa reshared this.
Crazazy @ my computer c:
in reply to mcc • • •mcc
in reply to mcc • • •I'm really struggling with my docs for this language being two "tutorials" I'm juggling constantly.
I have a
case operand of
0 => 0
1 => 1
2 => 2
3 => 3
...
I would like this to be
case operand of
0 | 1 | 2 | 3 => operand
...
neither | nor repeating => is allowed here. Both tutorials skim the definition of a "pattern".
Is there like a … language spec I could be reading here to get *exact* syntax? A BNF? Maybe the source is just readable. Should I read the source?
jjj
in reply to mcc • • •I don't know Idris 2 but googled a bit and maybe this could be closer to what you want? Might be possible for your use case but I am not sure. idris2.readthedocs.io/en/lates… But since you know OCaml, maybe you discarded that idea already
Views and the “with” rule — Idris 2.0 Documentation
idris2.readthedocs.iomcc
in reply to jjj • • •Thanks. I'm now hideously confused because I thought I already tried that and it didn't work.
Or are you suggesting "with" and "case" have different pattern/deconstruction rules?
jjj
in reply to mcc • • •mcc
in reply to jjj • • •cassie
in reply to jjj • • •mcc
in reply to mcc • • •I'm keeping a list of "issues to file on idris2 when I am done with this project" and HOO BOY am I ever filing this one (second time hitting)
mcc
in reply to mcc • • •Okay so I'm probably sounding like a broken record at this point but.
I want to xor two numbers. I find an "xor" in Data.Bits.
idris2docs.sinyax.net/data/bas…
Doc says xor is "Fixity Declaration: infixl operator, level 6". I guess that means it's an infix operator. Wrong? 📎1
EDIT: Or right?? uh social.treehouse.systems/@dysf…
*A frustration is I feel like I can't interpret docs without having other docs open.*
but, xor a b => this works
Except Nat doesn't conform to the Bits interface. So I'm stuck. 📎2
Data.Bits
idris2docs.sinyax.netdyssociative function
2026-10-17 21:36:57
Chuck
in reply to mcc • • •mcc
in reply to mcc • • •mcc
in reply to mcc • • •Well at least the cast operator in Idris is frickin magic
(The below works. It just figures out ip_idx is supposed to be a nat.)
✧✦Catherine✦✧
in reply to mcc • • •mcc
in reply to ✧✦Catherine✦✧ • • •mcc
in reply to mcc • • •I am *spectacularly* confused about when I'm allowed to nest expressions in this language as well as when I'm allowed to insert linebreaks and when linebreaks require indentation. i'd really, really like a BNF or other specific description of the parsing rules other than a set of examples.
(Incidentally, I can't find the "if then" construct documented in either "tutorial"— and remember, that's the only non-API documentation I've found. If/then definitely exists, but I can't find it documented.
mcc
in reply to mcc • • •I am now officially "frustrated" with this language
Chuck
in reply to mcc • • •mcc
in reply to Chuck • • •@ChuckMcManis I want to be clear this language is *very* comprehensible, maybe even more comprehensible than Haskell because the type system is less restrictive, **as long as the thing you want to do has an explanation of how to do it written in the manual.**
If it's in the manual, you look at the manual and go "oh, that makes so much sense!"
Chuck
in reply to mcc • • •Consistently opinionated is okay. Definitely better than MATLAB which seems to freely mix the concept of 'language' feature and 'extra cost library add-on' indiscriminately.
Somewhere I have the book "Learn you a Haskell for Great Good" where the "Good" has been lined out and replaced with "Trauma" 😆 which kept me away from functional languages ever since.
Chuck
in reply to Chuck • • •cassie
in reply to Chuck • • •mcc
in reply to mcc • • •How do I turn 🙁 Nat into Fin 64 🙁 apparently tossing off an "if < 64" isn't good enough. With arrays I could call an "inBounds" that returned Yes or No with magic predicates but I don't find anything such in Data.Fin.
BONUS WEIRDNESS: I imported Data.Fin and tried casting Bits64 to Fin 64, which I expected to fail because that's a fallable conversion, but instead I got the strangest type error on the *following* line. I need Rust try_into() somehow.
(Fin 64 is "numbers under 64")
mcc
in reply to mcc • • •Okay, status, end of day four (with change). My program can run the "sample" in the AOC project statement correctly. However when run on the puzzle input, it crashes (assert line 102). There are five smaller tests in the AOC statement, but to attempt them I need to add a verbose mode that lets me introspect the register state.
This is fairly satisfying (if not correctly commented) code, to me, even if each individual line required way too much blood and tears to write.
github.com/mcclure/aoc2024/blo…
aoc2024/17-01-cpu/src/puzzle.idr at d624dab20bb67f7ed79bb752c58086d323ba24fd · mcclure/aoc2024
GitHubprozacchiwawa reshared this.
mcc
in reply to mcc • • •As of now, I do not believe I could have written as much of this program as I did if I didn't have 20,000 Mastodon followers* including many members of types.pl. In an academic setting, I could have pestered a TA. But the Idris IRC is dead, and the Zulip is super responsive BUT if I'd made a Zulip thread for each problem above the majority of threads would now be mine. Maybe I couldve made one long "HELPME" thread idk
* Yes, the site says 42,000, but *way* more than half of those are spam bots.
mcc
in reply to mcc • • •🏳️🌈🏳️⚧️ Brie 🌧️🚴🏻♀️🍂✨ reshared this.
mcc
in reply to mcc • • •Me, thinking: Writing clear, relevant error messages is one of the hardest things in a programming language. It's harder in languages with inference and currying. My own languages have quite bad error messages. It's very unfair to bag on Idris for bad error messages.
Also me thinking: In Idris we don't say "expected (String, Bool) but got String" we say "can't find Applicative" and I think that's beautiful
"Yeah, applicatives just stopped existing for a moment"
"Forgot to pay your Monad Bill"
mcc
in reply to mcc • • •Alright, well that wasn't so hard.
*Blinks, looks around*
Wait, wasn't I supposed to be eating breakfast?
(Notes: - Notice the "expected output", separated by commas in the filename, is printed separated by newlines in the output; haha wow it's annoying when you write an algorithm as a chain of mutually recursive functions that end by tailcalling each other, and then realize you need to add one parameter)
Klara in the hidden land
in reply to mcc • • •mcc
in reply to mcc • • •Okay so
Sample works as expected
Additional examples in the problem statement work. Adding register display to verbose mode revealed one (1) bug and allowed confirming those end correctly.
Problem input completes without errors.
My output on the problem input, the website says, is incorrect.
The only thing left I can do is construct my own tests against the (unclear on several points) problem statement to find what misbehavior isn't captured in the samples.
This one is going to be… painful.
mcc
in reply to mcc • • •Only worked on this for part of the day, but I wrote a series of, in my opinion, *extremely* good functional tests— in my opinion, I write extremely good tests— systematically testing every opcode, combination of behavior, and operand code.
I found no problems. Something is wrong and I haven't found it.
The *one* thing I didn't test yet was the branch instruction, simply because I got sleepy. Oh my goodness I had *better* have something wrong with my branch implementation or I am in *trouble*.
mcc
in reply to mcc • • •Phillip
in reply to mcc • • •mcc
in reply to Phillip • • •Heribert Schütz
in reply to mcc • • •@phlip
I don't get it. Do we look at the same instructions? I'm using adventofcode.com/2024/day/17 , which does not contain the word "remove". It repeats three times that multiple output values should be separated by commas, apparently to make sure that answers are not rejected due to wrong formatting.
And I do not see a need for *manually* formatting the answer. It should not be too difficult to do it programmatically.
Or am I missing something?
BTW: A very interesting thread!
Day 17 - Advent of Code 2024
adventofcode.commcc
in reply to Heribert Schütz • • •Heribert Schütz
in reply to mcc • • •Jordan
in reply to mcc • • •mcc
in reply to Jordan • • •@jrose he never suggested using newlines; he simply said "output the number"
i think the commas are so that he can give samples with non-confusing results, and i think the comma removal is so that his answer checker can be as simple as possible. but it worries me, because unnecessary detail like that makes me afraid he's Up To Something, or there's a nuance my brain is just missing, or it hints at something awful in Part 2.
mcc
in reply to mcc • • •Sensitive content
mcc
in reply to mcc • • •THE PROBLEM WAS ME. The problem was the commas. I *wasn't* supposed to remove the commas, I was supposed to include them. The problem statement isn't even oblique like AOCs even are, he just worded the sentence in a slightly odd way and I confused myself. The version of my code that passed on the AOC author's full testcase set passes on my input. I didn't even spot this myself, someone pointed it out in my mentions.
But I regret nothing. Because writing exhaustive test cases is SIMPLY WORTH IT.
mcc
in reply to mcc • • •Sensitive content
Two additional notes:
- Now that I know commas are required rather than banned, I simply changed my program to print the commas itself in non-debug mode. Because why not
- I am terrified about part 2; there's so much room for terrifying swerves. One thing I suspect is that since both program output and program input are a comma-separated list of numbers modulo 8, we're going to be executing a series of programs that execute the output of the previous program
mcc
in reply to mcc • • •UPDATE: Hahaha, oh heck
Okay, so without explaining "Part 2", what I now need to do is alter my part 1 program so it runs in a loop, and the output is appended to an in-memory structure instead of sent to STDOUT. The most sensible way to do this would be a Perl test harness repeatedly invoking the exe and parsing the output.
I! Don't! Want! To be! Sensible! The point was not to write software but learn something. I think I now have an excuse to finally learn something concrete about "monads".
mcc
in reply to mcc • • •My program:
github.com/mcclure/aoc2024/blo…
Runs a simulation over time in the IO monad, calling "putStr" and "die" as appropriate. If I were in an imperative language, I'd just change those to append to an array and throw an exception.
But monads are "programmable semicolons", right? So I should be able to have one program parameterized over a monad, a "submit value" function, and a "early terminate" function. I should be able to emulate array.push_back() and throw. The monad just handles it.
aoc2024/17-01-cpu/src/puzzle.idr at 3c13d9276f958319bbaa59c58f4d4e074ce770df · mcclure/aoc2024
GitHubmcc
in reply to mcc • • •I mean, also I could just rewrite the program without a monad at all. I could do normal recursive techniques, accumulate my values in an accumulator, and terminate early with Either. But I already know how to do that, so it's not interesting. What's interesting is doing something I couldn't do, or couldn't do easily, without Haskell/Idris.
So I guess my question for Idris users is:
Do I "write my own monad"? Or is "IO" adequate for "emulate mutable state in the form of one accumulator list"?
lambdageek
in reply to mcc • • •The most educational approach is probably to do it all three ways:
1. normal recursive techniques
2. IO monad imperative program
3. Roll your own monad encapsulating the boilerplate from (1) that hopefully shows that the structure from (2) is not tied to IO, but to accumulating some state in the background and having some kind of unwind opration.
Folks will tell you to use monad transformers or effect frameworks. But I don't think that's nearly as educational as doing (1) and (3).
lambdageek
in reply to lambdageek • • •mcc
in reply to lambdageek • • •@lambdageek It is good thinking! One thing of note is that I need some kind of pause/resume feature ANYWAY, so that if one of my runs takes "too long" mastodon.social/@mcc/117468548… I can come back to it later.
One option would be to write the "normal recursive"/OCaml version first because I'm certain i can finish it within my time limit, and I can return latre and do the more-complex version without time pressure and AFTER reading, like, a book or three about this.
mcc
2026-10-19 16:36:35
lambdageek
in reply to mcc • • •Good news: coroutines are also a monad.
Bad news: I'm not sure there's a good way to arrive at the coroutines monad in a natural way from how you'd write the "normally", unless you just write all your code in continuation-passing style by default.
Also in this case doing the "IO monad imperative program" version is probably going to be a dead end because I think refactoring it out into a pause/resume version is not going to be very natural.
mcc
in reply to lambdageek • • •@lambdageek "coroutines are also a monad"
Oh, I am *so* happy to hear that.
And I think I was unclear, the halt/resume version is something I believe I can implement with Either. Like, I can implement that without even changing the program much using only features that exist in OCaml.
mcc
in reply to mcc • • •mcc
in reply to mcc • • •Heribert Schütz
in reply to mcc • • •Sensitive content
The length of the expected output list is known. So the program might die if this length is exceeded by the output list.
Yes, this feels hacky, but somehow you need to solve the halting problem.
And if you're at it, you could of course break an evaluation as soon as the output is not a prefix of the expected output.
So the CPU might keep the list of "expected remaining output" and "consume" it upon fitting output.
mcc
in reply to Heribert Schütz • • •Sensitive content
mcc
in reply to mcc • • •Current status: accumulating a list using value::rest and then having to reverse it at the end. oh geez these are real Ocaml hours here
Hey, did I see at some point Idris has a List variant in the standard library which is optimized for fast tail insertion somehow? Did I imagine that?
mcc
in reply to mcc • • •Right up until the last minute this language is giving me a cornucopia of "this thing I did before has stopped working suddenly and the error message doesn't hint why"
Here, a very simple "case" statement fails, because… because the variable I assigned to wasn't used. I was sincerely not sure if I was confused about the (seemingly undocumented) whitespace rules again. No, I just needed to use the result. But I wanted to write the expression before I tried to use it. Silly me!
mcc
in reply to mcc • • •Alright. Any Idris users awake?
I want to compare two lists. That's easy to implement recursively, and I THINK it's implementable with zipWith tho docs remain… vague ( idris2docs.sinyax.net/data/bas… what does zip do if the lists are of unequal length?)
…but! It *sounds* like something the standard library would have. And indeed I find a Interface-satisfying function exists in in Data.List.Equalities…
idris2docs.sinyax.net/data/con…
…but I can't import that.
I type this post, and the explanation jumps out.
Data.Zippable
idris2docs.sinyax.netmcc
in reply to mcc • • •…it's in contrib. List equality isn't in the "prelude" (default) or "base" (despite the name, not default; you have to specifically import base).
The doc doesn't *say* it's in contrib. But the *url slug* says it's in contrib. I only notice this when pasting the url into this compose box.
…Also, while writing this thread, I got Idris2 maintainers begging me not to use anything in contrib because that's all stuff that's GOING to be spun out into its own library but hasn't been yet. So, uh…
mcc
in reply to mcc • • •Oh right, I was going to ask a question. Any Idris users awake? Two part question.
1. idris2docs.sinyax.net/data/con… Do I understand write that if I can import the package containing this symbol, a == b and a /= b on `List int` will magically work?
2. Is it surprising that I changed my ipkg to say "depends = base, contrib" and despite this, "import Data.List.Equalities" fails in the Idris executable, and succeeds in the LSP? And also list1==list2 still fails with the mystery (?a->?f?a->?b error?
Data.List.Equalities
idris2docs.sinyax.netmcc
in reply to mcc • • •Wait. Wait. Hold on a friggin minute
Computer
Enhance
… this type is assigned female at birth ????
Benji Smith
in reply to mcc • • •demofox
in reply to Benji Smith • • •mcc
in reply to mcc • • •Okay. Whatever. Whatever!! At this point I go on tilt. I can't decode this documentation, I can't figure out why `idris2 -o` ignores my ipkg and `pack exec` fails without printing error messages. I know SML/NJ! I write my own list-equality helper. It takes seconds.
…oh wait, it's not letting me use the Eq interface. Odd. Fine, I'll compare ints.
…oh, there's… no such thing as… equality on ints. fine. Fine! I wanted Bits64s anyway. I—
OH COME ON HOW IS THAT NOT A COVERING FUNCTION??
mcc
in reply to mcc • • •At about this point a very nice types.pl user replies to point out that the reason my original == code, with Data.List.Equalities, did not work was because I mixed up |> and <|. Again.
…I…
I'm frustrated. At this point. I'm not concentrating well. I'm trying not to mention "COVID-19 post-viral syndrome" in this thread, or how much Benadryl I'm on.
Okay. Okay. It works now. As long as I run "pack exec". Which means I am now banned from getting error messages in the command line. Okay. Fine.
mcc
in reply to mcc • • •Please excuse me for my unprofessional outburst. With regard to whether my "listEq" implementation was a covering function. Although I'm still right.
EDIT: Im wrong. I was given a counterexample. I think what I should have matched in cases two and three was (_, []) and ([], _); since the case ([], []) was already excluded, those patterns can only match "lists of 1 or more items" in the _ positions, and it will work. I did not test it.
mcc
in reply to mcc • • •Also this… this is correct. This is absolutely correct. The problem was my |> / <| mixup, not which modules I had imported, and I don't have any need whatsoever for contrib, so I'm out of `pack` jail now. Okay. Alright. That's good. Okay. types.pl/@ionchy/1174710916268…
[QRT inset not provided because of the Mastodon 5 GUI reset dropping tomorrow. I've switched to masto-fe and can no longer quote boost.]
masto UI updatechy (@ionchy@types.pl)
masto UI updatechy (types.pl)mcc
in reply to mcc • • •Hey question if in Idris you feed the |> function into the <| function, like you execute <| |>
Does it unlock a quantum computing library
mcc
in reply to mcc • • •Sensitive content
So. The story so far: In part 1, I made an emulator for a gross ass mini CPU. I'm given a program for it. In part 2, AOC guy informs me this program is SUPPOSED to be a quine, but it has a bug; the initial "register A" value is wrong. I need to find the A that reproduces the program. So I run the program in a loop, incrementing A each time until the program output equals its own code. I know this works; it works on the sample.
But on my *assigned*program… well…
mcc
in reply to mcc • • •Sensitive content
(Ignore the "eq? True" there, I forgot a "not", it's repeating until it prints False).
I didn't finish my program, as of this second. I didn't get around to implementing the code to recover after invalid-program or infinite-loop failures (but that's ok, because it appears those failures never never happen on the program input). I have it printing output on every line, and STDOUT is *definitely* slowing me down.
Looking at the output, it's clear I don't need any of that.
mcc
in reply to mcc • • •Sensitive content
mcc
in reply to mcc • • •Sensitive content
The instruction set consists of a function that divides A by two, and a bunch of XOR ops. There's a jump function that jumps if A is nonzero. Implication: A is like a sort of logarithmic counter; the program whittles away dividing repeatedly by two until A hits zero. It's very clear the number of output digits scales linearly with the number of digits in A.
This means a linear scan is out. After running a pretty long time, my output has 8 digits. My target string has 16.
mcc
in reply to mcc • • •Sensitive content
So even if I'm more efficient and am not waiting on STDOUT, I can't (shouldn't?) count up to 16 digits by hand.
However, I'm *mostly* sure I can do something like a binary search. The XORs mean the output isn't smoothly increasing, but it's increasing on average, so a binary search will get me into the neighborhood, and maybe that'll identify a block of, I dunno, a thousand or a hundred "A" values that I can linearly scan and find my result.
…tomorrow.
mcc
in reply to mcc • • •Joe wills
in reply to mcc • • •mcc
in reply to Joe wills • • •Joe wills
in reply to mcc • • •mcc
in reply to Joe wills • • •Joe wills
in reply to mcc • • •mcc
in reply to mcc • • •Sensitive content
I'm laying in bed. I think about how the values in the input/output lists are all in the range 0-7, and wonder if the AOC taskmaster wants us to be thinking of them as an octal number.
I think about "comparing" lists. I realize I don't know which end to compare from. I make a decision. I get up and start doing a *manual* binary search. Why not?
I quickly find the numbers don't behave the way I hoped. Most numbers I pick turn into long strings of 4s, for some reason.
But.
mcc
in reply to mcc • • •Sensitive content
Treating my "goal" string as an octal number and looking at it in different bases revealed nothing interesting.
A regular binary search really gets me nowhere. I think: Wait, isn't this math bitwise/logarithmic? I try doing a "binary" search picking midpoints with 10^((log10(a)+log10(b))/2). [block 1 in image above]
That goes better, but not good enough. I quickly get two *broad* endpoints of my range, but can't reduce it further. [block 2 in image above]
But then—
mcc
in reply to mcc • • •Sensitive content
[block 3 in image above] I try looking at my input numbers in octal. I *immediately* realize that the number of printed "digits" in the output is exactly equal to the number of digits in my "A register" number represented as base 8. Hence: My answer will be n where
octal 1000000000000000 <= n < octal 7777777777777777. 15 digits.
This is the first concretely useful thing I've worked out so far.
mcc
in reply to mcc • • •Sensitive content
I'm unsure what to do next. I still think I need to do some kind of directed search, but maybe instead of thinking about magnitude I measure bit similarity and toggle bits one by one. I imagine implementing this in JS and making 48 checkboxes for input bits I can play with. I imagine my linear scan emitting a Unicode bitmap.
I have until 6 PM tomorrow to meet my one-week deadline.
I worry I'm going to have to *read* the program and figure out what it's *actually doing*.
mcc
in reply to mcc • • •There's something in the "sinyax" docs titled "Libraries.Utils.Octal". I don't find this in `pack query`, and it isn't in prelude. What is this, and how do I obtain it? It would speed up the thing I think I have to do next.
idris2docs.sinyax.net/data/idr…
Libraries.Utils.Octal
idris2docs.sinyax.netmcc
in reply to mcc • • •Sensitive content
Okay. Here's the commented "decomp" of the program I'm executing.
This is… not so bad. The only particularly "chaotic" step is 2. Critically, all of this math works on only one "octal" digit at a time. Each output "digit" is dependent on a single octal input digit, plus one other, *higher-magnitude* 3-bit slice cmhosen chaotically on step 2.
This means, I think, if I start with the most-significant digit and work "right", each output digit will "lock" and not change again.
mcc
in reply to mcc • • •Sensitive content
Brian Swetland
in reply to mcc • • •Sensitive content
mcc
in reply to Brian Swetland • • •Sensitive content
Robin Adams
in reply to mcc • • •TVTropes calls this the Password Slot Machine
tvtropes.org/pmwiki/pmwiki.php…
Password Slot Machine - TV Tropes
Contributors to TV Tropes (aka Tropers) (TV Tropes)Erin
in reply to mcc • • •Sensitive content
Erin
in reply to Erin • • •Sensitive content
Known-plaintext attack - Wikipedia
Contributors to Wikimedia projects (Wikimedia Foundation, Inc.)mcc
in reply to mcc • • •mcc
in reply to mcc • • •Sensitive content
Padding Oracle Attack. That's the term I was looking for. Although rereading the Wikipedia page it looks like I may have been confused about the term, and it may just be an *example* of this attack class rather than a *term* for this attack class.
defcon.social/@retsel/11747283…
retsel
2026-10-20 10:46:04
mcc
in reply to mcc • • •Sensitive content
So here's what I did. I changed my linear scan so instead of just counting up from 0, it takes a list of numbers from STDIN. This allowed me to make a file containing a batch of numbers I want to check all at once (which I filter through perl -e 'while (<>) { last unless /\d/; $_ = oct($_); print "$_\n"; }', since I never figured out how to access the documented octal support library in Idris). This lets me test every leftmost digit, every one-right-of-leftmost digit, etc…
mcc
in reply to mcc • • •Sensitive content
…I can test as many candidate numbers as I want at once and see the results in bulk. I do this to (see images above) find the correct digit one octal at a time left to right, each octal input digit matching one more digit in the output list.
This works great until my number suddenly "forks". On the 8th (1-indexed) digit, either 1 or 5 produces a matching result. So after that point, instead of testing 8 at a go I'm testing 16, simultaneously testing "world 1" and "world 5".
mcc
in reply to mcc • • •Sensitive content
This isn't so bad either except the forking *continues*; I'm quickly testing 3 parallel worlds, then one dies off. I basically manage until I hit digit 14 of 16, which turns out to have **six** different next options. I sort of do my best from there and eventually find a number: 165523097481149 (octal 4550533133267675).
It's wrong. It's too high. There are apparently multiple correct solutions, and AOC guy (so says the problem solution) wants the *lowest*. Which I fumbled.
Heribert Schütz
in reply to mcc • • •Sensitive content
Looks like you work with the program 2,4,1,1,7,5,1,5,4,1,5,5,0,3,3,0 for which 0o4550533133267675 actually is a solution.
But AOC (adventofcode.com/2024/day/17/i…) uses the program 2,4,1,2,7,5,1,7,4,4,0,3,5,5,3,0
mcc
in reply to Heribert Schütz • • •@hcschuetz first off, I'd appreciate answers being behind spoiler tags!
Second off every AOC participant gets individualized inputs specifically to prevent answer sharing like this.
Heribert Schütz
in reply to mcc • • •Sensitive content
I hope my previous post didn't spoiler too much. After all you already had this number.
And thanks for the hint about individualized inputs. Wasn't aware of this.
mcc
in reply to mcc • • •Sensitive content
Now that I've done the process by hand, though, I have a pretty good understanding of what it looks like, so now I'm in a much better position to automate this process, with the automation presumably not making whatever mistake my fallable human brain made to miss the true-lowest possibility.
I now believe I *could* finish this puzzle by my self-imposed deadline, but maybe I won't, since I got 1.5 hours of sleep last night and I'm leaving to go to the doctor. Uh… now.
mcc
in reply to mcc • • •mcc
in reply to mcc • • •Alright. Idris question. Do you just have like… a for loop. Hiding in this language somewhere. Yes I know how to do a loop with recursion. But you've already *got* monads/"do" and sometimes it's just true that the most semantically efficient way to communicate something is "for i in 1 to 8" or whatever. You seem to have range() . I think so anyway. I've thought I found things in the stdlib before and been wrong. idris2docs.sinyax.net/data/pap…
You didn't document "if" so maye you didn't document "for"
Data.Enumerate
idris2docs.sinyax.nettypeswitch
in reply to mcc • • •there's a for and for_ function in the prelude. the difference is that for_ doesn't care about the output from traversing the data structure (returns m () for a monad m) but for does (like map with side effects). probably for_ is what you want. idris2docs.sinyax.net/data/pre…
also you can do range comprehensions [ 1 .. 8 ] to get a range list: idris2.readthedocs.io/en/lates…
so it should be something like,
for_ [ 1 .. 8 ] $ \i => do
... something with i ...
Types and Functions — Idris 2.0 Documentation
idris2.readthedocs.iomcc reshared this.
mcc
in reply to typeswitch • • •Zoe : Void -> a
in reply to mcc • • •mcc
in reply to Zoe : Void -> a • • •Zoe : Void -> a
in reply to mcc • • •Zoe : Void -> a
in reply to Zoe : Void -> a • • •@typeswitch
So if take the Applicative to be IO:
> traverse print [1,2,3] -- traversing for a list
1
2
3
(returns: [(),(),()])
> traverse_ print (Just 1) -- traversing over Maybe
1
(returns: Just ())
> traverse_ print Nothing -- traversing over Maybe
(returns: Nothing)
One use case of the Maybe instance would be something like:
do result <- thingThatCanFail
for_ log result -- log the result if we got one
pure result
mcc
in reply to mcc • • •mcc
in reply to mcc • • •Currently drowning in a never-ending chain of writing basic "case" or "if" statements and getting unintelligible errors like "expected =>" on a => or "expected end of expression". Trying to not run to Mastodon for help on every one. Did encounter one thing that seems so actionable I'm considering filing it:
Why are members of the sequence "0..7" not Fin 8?
mcc
in reply to mcc • • •*deep breath* Okay, I'm…
I'm going to finish this. I'm going to do it.
When I set this down due to the PHP fire drill, I knew *exactly* what I needed to do, and how to get Idris to do it; but I could not get the Idris syntax to cooperate— due, I *believe*, to type errors the compiler was mis-flagging as syntax errors. I've got two reasons to hope I can just sit down and get things working.
One: This post… types.pl/@ionchy/1174794602464… which might be the thread if I pull it, things start working…
masto UI updatechy (@ionchy@types.pl)
masto UI updatechy (types.pl)mcc
in reply to mcc • • •Two: Holes. Perhaps holes will save me.
When I used to write a lot of OCaml, I got into this habit of writing things in a particular order, like chiseling a statue in reverse. I'd write things "in to out", smallest and most basic things first, larger scope last. This is because OCaml's extreme type inference lead to "spooky action at a distance", so if I wrote the small things last, a minor error in a small thing could cause a type error in a big thing (e.g., in entirely the wrong place).
mcc
in reply to mcc • • •mcc
in reply to mcc • • •Anyway, Idris/Haskell (or just GHC?) have this "holes" idea, where you can drop a "placeholder" value, prepend stuff with question marks, and Idris will just Not Make Assumptions about that bit. You can write your code out-to-in, while still getting the "chiseling" effect. In theory. Maybe I could learn that.
Problem: Yesterday my laptop rebooted (desktop linux seems to crash more in 2026 than it did in 2006) and now the Idris LSP won't wake up. Sublime Text LSPs do that sometimes. Aaaaargh!
samir, slightly sozzled
in reply to mcc • • •mcc
in reply to samir, slightly sozzled • • •samir, slightly sozzled
in reply to mcc • • •Khleedril
in reply to mcc • • •Kalle Hallivuori
in reply to Khleedril • • •mcc
in reply to mcc • • •Oh. I … hm. I tried, in a terminal, launching idris2-lsp. And then I killed it with CTRL-C. And suddenly Sublime started behaving.
????
(It is possible, a little unlikely but possible, I am the first person to ever successfully use the Idris LSP with Sublime Text. I had to write my own language configuration for the Sublime LSP plugin. I didn't know how to do that before this project.)
mcc
in reply to mcc • • •Okay, is frickin'…
Is Sublime Text the problem? Has Sublime Text been the problem this whole time?
(Images 1,2) I understand this error. I *understand it*. What I don't understand is what it's telling me I need to do to fix it. A value X is a fin16 and it's being used at a site Y expecting a nat, or vice versa. What I expect to see is X and Y underlined. Instead I get only X, which as far as I know is *untyped at the underlined point*. I *assume* the .. coerces it into a nat.
(post 1 of 3)
prozacchiwawa reshared this.
mcc
in reply to mcc • • •Oh, and I can *only* mouseover the "0". If I want to lookup the type of "shiftL" or "digit_idx", I can't.
If I run in the command line, it gets weirder. I get a nice ascii art underline which seems to be trying to underline the site of the error, but (1) it's a *different* site than the LSP underlines, and (2) actually, it's not underlining anything at all. the underline spans 3 symbols.
I want *both* underlines, and ideally, I'd get the same underlines in every tool I used.
(post 2 of 3)
_Έλλεν Εμίλια Ά. Arson Τζαϊλου
in reply to mcc • • •mcc
in reply to mcc • • •So, Idris users, here's my question for you:
* Is this what you see in your editor / IDE? *
Am I seeing some kind of *error* in the LSP when it talks to Sublime, or an error in Sublime's LSP bridge? Someone earlier mentioned *their* IDE, in Idris, gives you a list of holes. If I have that I haven't found how to activate it. Would a more Idrisy IDE mean I could get positions of all four of "Integer, Integer, Fin 16, Nat"? and not just "well, eventually this "0" unifies with something bad" (3/3)
mcc
in reply to mcc • • •In the absence of an answer to the above, I return to "holes", and the hope that "holes" offer. The first thing I try: I turn the usage site for `digits` (the thing containing the bad "0") into a ?hole, so I can mouse over "digits" and see what type it is if nothing unifies with it. This is how I'd have debugged this with Merlin if I got an unhelpful error in OCaml.
…
Nope!!! For some reason, in this *one* case, mousing over digits gives me what I think is *the type of the entire do block??*
mcc
in reply to mcc • • •Okay!! Fine!! I'll just use the Rust Trick!! It turns out the Rust Trick works in Idris. Fine! I'm writing Rust now!
(explanation in alt text)
mcc
in reply to mcc • • •I agree, but literally the entire point of this entire project was to see if I could find something better than Rust 🙁
infosec.exchange/@cyberquixote…
Hopeless Noosphere Situation Warrior :catte: :asexual_flag: (@cyberquixote@infosec.exchange)
Hopeless Noosphere Situation Warrior :catte: :asexual_flag: (Infosec Exchange)mcc
in reply to mcc • • •With the refining tool of "let () =", and writing some *incredibly* ugly code (if I trusted this syntax enough to split things across linebreaks, writing this language would be easier), I nail the problem down.
The problem is "this function requires a number that is proven to be under 64. instead, you gave it a number that is proven to be under 21".
…
I understand why the type system differentiates them.
But why is there not a *cast*???
Numbers under 21: MAY OR MAY NOT be under 64??
mcc
in reply to mcc • • •Notes:
- Previous comment really is just me voicing frustration; I know how to work around this, which is to construct a Fin 64 the first time around. It will be less elegant code, but I'll manage. I *am* very frustrated, though.
- What I'm actually doing for the record is converting a number of octets to a number of bits. What I'd ideally want is a function that can multiply a Fin 21 by 3 and get a Fin 63. This doesn't… *seem* to exist. In the obvious place. Hm. idris2docs.sinyax.net/data/bas…
Data.Fin
idris2docs.sinyax.netmcc
in reply to mcc • • •mcc
in reply to mcc • • •Okay. Jeepers. Jeepers!!! No errors. I think by now I can sincerely say the single design decision about Idris that caused the most difficulty over this project is the decision to use Fin for the bit-shift argument to the bitwise left-shift library function.
Hey Idris folks. Say I have two lists (A,B) and I want to generate all tuples (a,b) that can be created out of one member of A and one member of B. Is there a library function for that? I can write that but it sounds library-function-y.
typeswitch
in reply to mcc • • •ok, so, I can't test right now but I believe the magic incantation is:
(,) <$> xs <*> ys
where xs and ys are the two lists.
The way this works is (,) is a binary function that turns two values into a pair of values ... \ a b => (a,b)
(,) <$> xs maps (,) over xs, in fact you could write map (,) xs instead, since <$> is another way to write map. This gives you a list [ (,) x1 , (,) x2 , ... , (,) xn ]
then <*> ys takes this list of functions and applies each y in ys to each function.
prozacchiwawa reshared this.
mcc
in reply to typeswitch • • •dyssociative function
in reply to typeswitch • • •mcc
in reply to dyssociative function • • •Interfaces — Idris 2.0 Documentation
idris2.readthedocs.iotypeswitch
in reply to dyssociative function • • •mcc
in reply to typeswitch • • •@typeswitch I wound up going with this solution out of all of them because it let me skip a "map" (I was originally going to map the tuple list after forming it)
let next_candidates = (.|.) <$> candidates <*> digits
What this does… may or may not be clear, but I assure you it's very appropriate to the problem I am solving
typeswitch
in reply to mcc • • •yesss my plan of showing Applicative notation paid off ^^
(well, it wasn't some ingenious plan, it's what I would use in this case in Haskell or Idris, and I remember being mistified by the definitions and type signatures of Applicative until I saw some examples like this)
mcc
in reply to typeswitch • • •@typeswitch i sincerely did launch this project with the single goal of "okay on puzzle 7 i used haskell and learned what a monad is, on puzzle 17 i'll use idris and learn what a applicative is"
i'm not there yet but i can come back next week
mcc
in reply to mcc • • •Oh my god. The Idris users replied by giving me this wacky Do construction and unless this is just implementing `zip` it appears to work. Apparently the thing that turns this into a combinatorics engine instead of side effects is assigning it to a list, which puts you in the List Monad. This is Perl. This is literally Perl and the magic "List Context". Moreover, *this is the specific feature of Perl that blew up in my face and made writing the Perl script upthread take 8x as long as it should*
mcc
in reply to mcc • • •mcc
in reply to mcc • • •Tolerable, but odd: Although I'm pretty sure I've successfully used the | operator for bitwise OR in actual Idris code, in the *REPL* I can only access bitwise OR by writing it as (.|.)
No other sequence of characters works. Not `|`, not `.|.`
ME: Hey I wanna do bitwise arithmetic
IDRIS2: Okay, first draw me a picture of a butt.
ME: …
IDRIS2: Come on man, do it
mcc
in reply to mcc • • •Roy
in reply to mcc • • •mcc
in reply to mcc • • •samir, fake programmer (@samir@functional.computer)
samir, fake programmer (Lambdadon)Sophie of Ratsnake Games
in reply to mcc • • •mcc
in reply to mcc • • •Remember my feral list equality function that turned out to be unnecessary? Well it's back, and it compiles now, and is actually useful. This would probably look more satisfying as code if the first three clauses returned "=> True => False => False" but I actually do need the asserts.
I think…if I write a function that converts a list of octal digits into a number possessing those octal digits…the program will just work. I think it will work on the first try. Unless I forgot a "reverse". Or two
mcc
in reply to mcc • • •…wait a minute. Isn't what I want just foldl with `λ x y = (x << 3) | y`?
export octal_fold: Bits64 -> Bits64 -> Bits64
octal_fold a b = (.|.) (shiftL a 3) b
So I just plug that in and…
… what?
(This one went away if I cast [1,2,3,4] to List Bits64 but I can still be annoyed about it. By the way, OCaml likes foldl and Haskell likes foldr, right? Which one does Idris2 prefer?)
Paul Khuong
in reply to mcc • • •Caden
in reply to mcc • • •mcc
in reply to Caden • • •mcc
in reply to mcc • • •This last bit of debugging would be going so much easier if I could just figure out why there is a documented module named "Libraries.Utils.Octal" which doesn't actually exist in the standard library. mastodon.social/@mcc/117471914…
Maybe I should give up and write my own int-to-octal-string function.
mcc
2026-10-20 06:52:46
stand a little out of my sun🍉
in reply to mcc • • •mcc
in reply to stand a little out of my sun🍉 • • •mcc
in reply to mcc • • •So functional programming likes linked lists, and the standard way to build a list in ML derivatives (which includes Idris) is not a ".append" like in C, JS, Rust but newelement::list, i.e., a prepend operation. This means functional programming involves a lot of generating a list then reversing it.
Anyway, what I've figured out is my automated solution search, now that it's finished, *actually* finds solutions which print *the target output, but backward*.
Sigh.
Paul Khuong
in reply to mcc • • •mcc
in reply to Paul Khuong • • •@pkhuong idris2docs.sinyax.net/data/bas…
…hm. Well, next time I write something in Idris I'll consider that
Data.List
idris2docs.sinyax.netmcc
in reply to mcc • • •Paul Khuong
in reply to mcc • • •mcc
in reply to Paul Khuong • • •mag
in reply to Paul Khuong • • •@pkhuong unsure if it's in the prelude but idris does come with a snoclist implementation yeah
alternatively, snoclists are a pretty good candidate for learning how to define a type in idris
mcc
in reply to mag • • •mcc
in reply to mcc • • •Okay. Yes. Straightfoward. I intentionally left my output reversed because I needed to compare it to the target string rightmost-value-first, but then I forgot to reverse the target string. Pretty quick to find.
This project is officially a
FAILURE
Because it took 12 days instead of the planned 7. If I'd finished it yesterday I'd have complained "that's 7 days, it's just dealing with PHP and '4' left me unable to work on it tuesday through friday" but it still took me two days once I resumed.
Sophie of Ratsnake Games
in reply to mcc • • •Andi
I think you're allowed to take sick leave from your AoC challenge run
mcc
in reply to Sophie of Ratsnake Games • • •mcc
in reply to mcc • • •There turned out to be exactly 16 different integers that were correct solutions to my problem, and then one I found by hand was not the lowest. It appears I made a mistake on digit 3.
I am now at 11/25 puzzles completed, 9/11 completed in the time limit. I think I am going to put this project down for a while, this one puzzle was brutal. Especially the second half.
Pity, because my next two languages were Zig and MIR ( github.com/rust-lang/rustc_pub… ) and I was legit really excited about those.
GitHub - rust-lang/rustc_public: Define compiler intermediate representation usable by external tools
GitHubmcc
in reply to mcc • • •Here's my solution code for "part 2", but of course it's confusing unless you've read the "spoilers" blocks above and know what part 2 is even meant to be doing.
github.com/mcclure/aoc2024/blo…
You may find line 276 interesting.
aoc2024/17-02-cpu/src/puzzle-digits.idr at d2e2e2c402bb3a85d643d4f5c9305a727c446737 · mcclure/aoc2024
GitHubmcc
in reply to mcc • • •mcc
in reply to mcc • • •Allan A
in reply to mcc • • •mcc
in reply to Allan A • • •pfriedma
in reply to mcc • • •Ooh you should absolutely try elixir!! I mean I also really like erlang, but elixir's additions IMO make it really lovely to work with.
Edit: and/or gleam for that matter- I hadn't checked Gleam out but it looks very neat!
@noodlenog
mcc
in reply to pfriedma • • •@pfriedma @noodlenog here's my todo list
files.mastodon.social/media_at…
Imagine Idris were crossed out with a blue star
pfriedma
in reply to mcc • • •Hrmm... I had good experience with trying erlang first because it made the things often considered quirks of Elixir (and I'm going to imagine Gleam) make sense. But I can also see how trying elixir first would let you just appreciate it (or not) for what it is.
But you should definitely consider doing them somewhat together - the BEAM family as it were
@noodlenog
mcc
in reply to pfriedma • • •Allan A
in reply to mcc • • •Looks like a fun, mind-expanding list.
I’ve got a Racket book here, so I might play with that soon! All I know about Lisp style languages is that they came forth from MIT and Bob Kanefsky wrote a filk song called “God Wrote in Lisp Code”
Janne Moren
in reply to mcc • • •Rust would never have gotten all this traction if they hadn't done the work from the very star to get truly useful, informative error messages at every turn.
Shows how even a very complex language becomes usable when it tells you what's going wrong and how you (probably) want to fix it.
⁂ Fish Id Wardrobe
in reply to mcc • • •Sophie of Ratsnake Games
in reply to mcc • • •samir, slightly sozzled
in reply to mcc • • •2 .|. 1?mcc
in reply to samir, slightly sozzled • • •Video Game King
in reply to mcc • • •mcc reshared this.
mag
in reply to mcc • • •mcc
in reply to mag • • •Clifton Royston
in reply to mcc • • •Oh no...
The single worst feature of Perl IMO is the operators that do entirely different things in scalar and list contexts.
i think it messes with people's memory for what operators exist and which do what.
I strongly suspect this is one reason, for example, that (years ago) one of my team who knew Perl quite well forgot that it had a string length function and wrote his own.
(I used to be a big Perl nut)
_Έλλεν Εμίλια Ά. Arson Τζαϊλου
in reply to mcc • • •Data.Fin
idris-lang.orgprozacchiwawa
in reply to mcc • • •i don't use idris in lsp mode, i use the idris2 mode in emacs instead.
i admittedly prefer not having things interrupt when editing and then having a list of errors when i call for it (M-x compile).
The idris mode looks like this normally for me.
if you make an ipkg file right away, C-c C-l will show the holes in the current file. I never let an idris file with errors persist because admittedly the error messages aren't easy to understand and i find them more difficult to reason about than other languages.
holes though, you can always put one in and then reason about the difference in type.
njplschy
in reply to mcc • • •because
idoesn't know anything about what list was given, all it knows is that it's anIntegeryou probably want
allFins 8for all the numbers inFin 8iterateNto apply(fun x => shiftL x FZ)onleight times and collect the intermediate results in a listnjplschy
in reply to mcc • • •for [1..8] (\i => ...)(the list comprehension syntax is noted here idris2.readthedocs.io/en/lates… although it's unclear whether the endpoints are inclusive lol)
Types and Functions — Idris 2.0 Documentation
idris2.readthedocs.ionjplschy
in reply to njplschy • • •ifis documentedmcc
in reply to njplschy • • •Ellie
in reply to mcc • • •Jamie is a friendly nut
in reply to mcc • • •because I am catching up on my feed a day late, I had to check the timestamp to see if this keysmash was still about the problem you were working on or if it was about private key = 4
either way I'm counting this thread as dramatic irony for real life
mcc
in reply to Jamie is a friendly nut • • •Somē
in reply to mcc • • •retsel
in reply to mcc • • •Sensitive content
mcc
in reply to retsel • • •Sensitive content
Thomas Hurst
in reply to mcc • • •Sensitive content
TENEX infamously had an attack like this based on virtual memory paging. You'd put the first character of the password to test at the end of a memory page, leave the next page unallocated, and if the next page was faulted in after you tried it you knew you got that character correct. Rinse repeat.
sjoerdlangkemper.nl/2016/11/01…
I don't think that answers your question, but I thought it was an interesting example!
The password guessing bug in Tenex
Sjoerd Langkempermym
in reply to mcc • • •Sensitive content
ROTOPE~1
in reply to mcc • • •perl has the "spaceship" operator, it only makes sense that somebody else would have the Cosmic Ark operator
reshared this
mcc and ClaudioM reshared this.
Tim Chase
in reply to ROTOPE~1 • • •Hah, I dropped into the thread with @rotopenguin's post, expecting some light-hearted programming-language humor, not some "Epic trials of MCC" thread with 1.414×10⁴ posts 😆
You have a great deal more fortitude for this adventure than I would ever have, but it sounds like you're having fun and learning stuff which is the important bit 😁
mcc
in reply to Tim Chase • • •typeswitch
in reply to mcc • • •Sensitive content
what about listEq [] [1,2] or listEq [1,2] []. these are not handled in the case blocks above. (the left hand side of the two False cases is not general enough).
also it couldn't find Eq int because int is not Int (need to capitalize type names, lowercase types are type variables)
mcc
in reply to typeswitch • • •Sensitive content
Janne Moren
in reply to mcc • • •mcc
in reply to Janne Moren • • •Janne Moren
in reply to mcc • • •jjj
in reply to mcc • • •Disregarding my previous promise to know what I am talking about:
For your code that starts with
listEq : List (Eq a) -> List (Eq a) -> Bool
I think the interface restriction needs to be written like this:
listEq : Eq a => List a -> List a -> Bool
For your specialized integer code, I think you need to capitalize your int as Int or maybe Integer (so List int should be List Int)
Both these suggestions based on what I skimmed at idris2.readthedocs.io/en/lates…
As for the covering, I don't know.
I really like following you Idris 2 adventure, I wish to learn it myself some day.
I remember my intense struggles and frustration when learning Haskell a long while ago.
Interfaces — Idris 2.0 Documentation
idris2.readthedocs.iomcc
in reply to jjj • • •njplschy
in reply to mcc • • •it's expecting something of type
(?a -> ?f ?a) -> ?bso that's just what(|>)takes as the second argument, but why do you have that there anyway?pure (list1 == list2)should be enoughmcc
in reply to njplschy • • •@ionchy Thank you very much.
I got addicted to @@ back in the SML/NJ days…
njplschy
in reply to njplschy • • •(==)should just work without importing anything because it's provided by the Eq typeclass idris2docs.sinyax.net/data/pre… so ifahas an Eq typeclass then so doesList aautomaticallyPrelude.Types.src.html
idris2docs.sinyax.netmcc
in reply to njplschy • • •the kneads of the many
in reply to mcc • • •Based on what I can see of your program, I think the issue is with `|>`, since that's reverse function application: that is to say, `5 |> show` is effectively sugar for `show 5`. That means you're trying to take the result of `output == cpu.prog`, which is `Bool`, and apply it as a function to the value `pure`, as though you wrote `(output == cpu.prog) pure`.
Again, I can only see what's not obscured, but with those assumptions, I think you might just want `pure (output == cpu.prog)`?
mcc
in reply to the kneads of the many • • •SackOfBones (any/all)
in reply to mcc • • •youtu.be/3Dc_cnj1PEc?t=12
I Like Your Funny Words Magic Man Full Clip
Nolan (YouTube)cliffle
in reply to mcc • • •Andre Videla
in reply to mcc • • •both are sensible. In the first case you would parameterise over a monad that has two actions. this is the kind of things you can do in haskell with monad transformers. If you want to use
IOyou can have anIORefholding your state and mutating thatIORefas necessary and do everything inIO.Both of those are nice experiments in their own right I would encourage you to do them.
If you want to do something that's idris-specifc, here is an idea: Monads can be more powerful in idris because they can constrain what actions you're allowed to take at any point. For example you could write a monad that does not allow you to sequence further actions once you've existed the program, I wrote a gist about it juts now gist.github.com/andrevidela/3b…
This went off the rails but should be a fun example of what we can do in Idris but not in other MLs
GistAndre Videla
in reply to mcc • • •By the way if you need to add one parameter post-hoc you can add a
parametersblock around the functions that need it idris2.readthedocs.io/en/lates…Note that those argument can’t be modified when calling other functions in the same
parametersblock, so it’s not necessarily what you need. it’s the mathematical definition of “parameter”Modules and Namespaces — Idris 2.0 Documentation
idris2.readthedocs.iomcc
in reply to Andre Videla • • •Andre Videla
in reply to mcc • • •the curly braces are used to introduce and manipulate implicit arguments, argument that you dont write down at call-site and let the compiler insert for you. Usually you can omit them and the compiler knows what you mean. For example
This is secretly
This means that every call to the function
lengthautomatically takes an extra argument that is inferred and inserted by the compiler.In fact, that’s how polymorphism/generics work too:
This is syntax sugar for
The
0here indicates that the value does not appear at runtime, we want to erase types away most of the timedyssociative function
in reply to Andre Videla • • •itym
dyssociative function
in reply to Andre Videla • • •{}Sophie of Ratsnake Games
in reply to mcc • • •mcc reshared this.
Blake C. Stacey
in reply to mcc • • •Daniel Lakeland
in reply to mcc • • •Well reading that thread convinced me never to ever look at Idris2 or Haskell or Ocaml or any of those crazy languages that ive looked at before and said NOPE.
I'm a LISPy person though, so, theres no accounting for taste.
mcc
in reply to Daniel Lakeland • • •Daniel Lakeland
in reply to mcc • • •dixego
in reply to mcc • • •Briala
in reply to mcc • • •cassie
in reply to mcc • • •mcc
in reply to cassie • • •cassie
in reply to mcc • • •Chris Ford
in reply to mcc • • •Ah, getAt is the one that returns a Maybe and it's in Prelude.Types.List.
Nat -> List a -> Maybe a
Chris Ford
in reply to Chris Ford • • •Irenes (many)
in reply to mcc • • •Zoe : Void -> a
in reply to Irenes (many) • • •Erin, the OSHA denialist
in reply to mcc • • •for some weird reason it makes sense to me.
Should I check out Idris 2?
mcc
in reply to Erin, the OSHA denialist • • •@ekatwired possibly, how do you feel about haskell?
it's a neat language in a lot of ways and i'm not sure i've encountered any objections that don't come down to either "this documentation needs some work" or "these error messages need some work". similar to perl, it appears to be a fantastic language as long as you already know it
DJ Sundog from the *new* toot-lab
in reply to mcc • • •Grace Jones - Pull Up To The Bumper
GraceJonesVEVO (YouTube)JodiTheEntitled
in reply to mcc • • •dixego
in reply to mcc • • •mcc
in reply to dixego • • •dixego
in reply to mcc • • •scrottie (he/him/them)
in reply to dixego • • •Black Perl - Wikipedia
Contributors to Wikimedia projects (Wikimedia Foundation, Inc.)dixego
in reply to scrottie (he/him/them) • • •scrottie (he/him/them)
in reply to dixego • • •scrottie (he/him/them)
in reply to mcc • • •@program Extremely primitive and probably long completely broken, but a long time ago, I did a strong/incremental typing implementation in Perl:
metacpan.org/pod/typesafety
If anyone ever actually used it besides myself, I never heard about it.
Client Challenge
metacpan.org∴ esoterik ∴
in reply to scrottie (he/him/them) • • •@scrottie nice! i wrote a "runtime" version of type-checking for oo perl that we used at one of my old jobs. basically the goal was to get a backtrace at the place you passed undef or a weird type, instead of the incomprehensible place it might crash later.
it mean that every single method we wrote had some "type-annotation" boilerplate and ended up feeling like "java-in-perl" but it worked surprisingly well. @mcc @program
Greg
in reply to mcc • • •mcc
in reply to Greg • • •Greg
in reply to mcc • • •rntz
in reply to mcc • • •map_right is just map. Either is a Functor (every Monad is a Functor), so it supports map: idris-lang.org/Idris2/prelude/…. you can also discover this at the repl with :search
Main> :search (a -> b) -> Either err a -> Either err b
Prelude.Types.map : (a -> b) -> Either e a -> Either e b
Main> map (+1) (the (Either String Int) (Right 2))
Right 3
but :search produces no results for the analogous type for mapping over Left so I think it might not exist. You can just implement it yourself though.
Prelude.Interfaces
idris-lang.orgrntz
in reply to rntz • • •Sensitive content
mapLeft : (a -> b) -> Either a x -> Either b x
mapLeft f (Left x) = Left (f x)
mapLeft f (Right x) = Right x
or, as @Andrev points out:
mapLeft : (a -> b) -> Either a x -> Either b x
mapLeft = mapFst
Andre Videla
in reply to rntz • • •mapFstfromBifunctorfor whichmapSndis the same asmapfromFunctorand defined asbimap f idrntz
in reply to Andre Videla • • •erincandescent ⎔
in reply to mcc • • •Jencel Panic
in reply to mcc • • •cassie
in reply to mcc • • •mcc
in reply to cassie • • •cassie
in reply to mcc • • •(I also do not like this, I would much prefer real names)
mcc
in reply to cassie • • •@porglezomp Always?
OK. Thanks
erincandescent ⎔
in reply to cassie • • •@porglezomp this is, to my mind, backwards x.x
but i guess thats just too much exposure to Rust et al
Krzysztof Sakrejda 🏳️⚧️ 🏴☠
in reply to mcc • • •prozacchiwawa
in reply to mcc • • •Data.Fin
idris-lang.org_Έλλεν Εμίλια Ά. Arson Τζαϊλου
in reply to prozacchiwawa • • •mcc
in reply to _Έλλεν Εμίλια Ά. Arson Τζαϊλου • • •_Έλλεν Εμίλια Ά. Arson Τζαϊλου
in reply to mcc • • •prozacchiwawa
in reply to _Έλλεν Εμίλια Ά. Arson Τζαϊλου • • •@fogti
may or may not be useful, but what was in my brain was something like this. bound is a fin of the correct size for the input vect in doWithV5, but the vect must be at least size 5. Since index uses fin, it makes it possible to pass on the vect bound, have it be a certain size without knowing the specific size inside doWithV5.
module Main
import Data.Nat
import Data.Fin
import Data.Vect
doWithV5 : {n : Nat} -> {default 5 x : Nat} -> (prf : LTE (S x) n) -> {default (natToFinLT {n=n} x) bound: Fin n} -> Vect n t -> Maybe t
doWithV5 _ _ = Nothing
main : IO ()
main = do
let
p1 : LTE 6 7
p1 = lteReflectsLTE 6 7 Refl
let _ = doWithV5 p1 [1,2,3,4,5,6,7]
-- cant' prove
-- let _ = doWithV5 ?p2 [1,2,3]
putStrLn "success"
_Έλλεν Εμίλια Ά. Arson Τζαϊλου
in reply to prozacchiwawa • • •prozacchiwawa
in reply to _Έλλεν Εμίλια Ά. Arson Τζαϊλου • • •@fogti
sorry didn't explain well so re-replying
the point of the fin conversion is basically as a stand in for "does my x fit in the vect i was given". thinking on it, there's no reason you couldn't just prove LT directly, but when i was writing it i was thinking: the function should be exposed to a Fin bound that is at least the size we want but ultimately up to the size of the vect.
likely more complicated than it needs to be though i suppose.
Sola
in reply to mcc • • •dixego
in reply to mcc • • •cliffle
in reply to mcc • • •Pete Alex Harris🦡🕸️🌲/∞🪐∫
in reply to cliffle • • •@cliffle
It seems like it'd be a problem if you ever wanted the tail of a List1 in the usual way.
Huh. Is a:::b just not defined for b as an empty list? Is that how it works?
[edit] No wait, that should be fine. That'd be a List1 with one element. But then I'm confused. OK, I think I get it. In a:::b, b is any List, but List1 doesn't include [] as an alternative. There has to be an a.
jamienvc ⚧️
in reply to mcc • • •Sola
in reply to mcc • • •Ölbaum
in reply to mcc • • •{ id: d2718, ok: 🇵🇸🌈🏳️⚧️🇺🇦 }
in reply to Ölbaum • • •I started using LaTeX in the late '90s, and I STILL don't know whether "badness 10000" is an error code or a quantification of the magnitude of the problem.
cassie
in reply to mcc • • •Jim Rootham
in reply to cassie • • •cassie
in reply to Jim Rootham • • •rntz
in reply to mcc • • •you are really suffering here due to not understanding monads I think. (But the error messages and action at a distance are not helping.)
You want: let x = lines spec
Not: x <- lines spec
I think. But I’m guessing - that “let x = lines spec” is Haskell syntax, dunno if it’s valid Idris, currently on phone.
rntz
in reply to rntz • • •brief monad tutorial: with monads you must distinguish IO String from String. weird error? maybe you mixed them up.
do let x = foo; ...
is just a let-binding, so if foo: String, then x: String. if foo: IO String, then x: IO String - probably not desirable. instead:
do x <- foo; ...
now if foo: IO String, then x: String; it *runs* the computation. foo must be an IO-thing (or some other monad instead of IO, but each do-block is inside exactly one monad), otherwise this will type error.
rntz
in reply to rntz • • •having to maintain this distinction everywhere can result in a lot of code noise. (pure: a -> IO a) is an example: it's used when you need to just shove something in a monad. so (do x <- pure y; ...) is exactly the same as (do let x = y; ...). Often pure is used if you have two branches, one of which needs to be in a monad to do some effect, but the other does not.
I can infodump further about monads but won't unless you ask.
Andre Videla
in reply to mcc • • •depending on how you feel more comfortable with you can write
And this will handle the error when the file isn't read properly.
The compiler's error message contains all the information you need to figure out what's wrong, although in a cryptic way. it says "I expected an IO, but you gave me a list". if you run
:t linesyou will see that it does not return anIObut it returns aList. You can only usex <- fwhenfreturn the same monad as all the other expressions in thedoblock. And because you started thedoblock by usingIOyou can't switch it to usingListat this point, although it would be valid in a different context (and that's why the message is a bit cryptic because we can't be sure what if you meant to use List and used IO by accident, or the other way around)Andre Videla
in reply to Andre Videla • • •I failed in my self-imposed goal to explain it without using the word
Monadso to atone for my sin I will give a simple explanation:A monad is a "container type", like
ListorIOthat you can "flatten":flatten : List (List a) -> List ameans List is a monadjoin : IO (IO a) -> IO ameansIOis a monad.Any
fwith a functionf (f a) -> f ais a monad (modulo details etc etc).This is usually not exposed or visible in other programming languages because they don't have a way to give a type to
f. But in Idris you can go in the repl and ask "what's the type ofList" or "what's the type ofIO" and it's going to tell you:that is, any "container type" takes a type in argument and returns another type. And so every monad is a
Type -> TypeAndre Videla
in reply to Andre Videla • • •cassie
in reply to mcc • • •ftr the issue is you don’t want `spec <- lines spec`, you want `let spec = lines spec`. But yeah that’s a bad error message.
The issue here is you’re saying “I want to be in the list monad now” with that bind, and it’s mad that you’re trying to be in both the list and IO monad in the same block.
mcc
in reply to cassie • • •Zoe : Void -> a
in reply to mcc • • •Vélimir
in reply to mcc • • •let and <- are two different things !
<- acts as both let and sorta-unwrap.
do blocs are always about a specific monad instance – here IO – and you can only unwrap that same instance inside. Simplified: if you call something that returns IO a, you should use <-. If you call something else, use let.
Here you called lines which returns a list. A list turns out is a valid monad instance (it does cool non-determinism stuff). So haskell is confused because it thinks you want to unwrap a List, which is possible in a do block on List, but you're in a do block on IO.
Anyways, yeah the error messages suck ass. As someone that recently learned haskell I agree that they don't tell you much.
I can only recommend once more that you read "learn you a Haskell for great good" because you seem confused about using monads
Jonathan Lamothe
in reply to Vélimir • •doblocks. They're a useful abstraction tool, but I think they sometimes abstract away too much. The<-vs.letconfusion is an example of this.Vélimir
in reply to Vélimir • • •Gaelan Steele
in reply to mcc • • •I think you want
let spec = lines spec
instead of
spec <- lines spec
because lines returns List String, not IO (List String); the <- syntax is for when the thing on the right-hand side returns an IO.
the explanation for why that’s the error message you got contains the word “monad”; one sec, I’ll try my best in a further message
Gaelan Steele
in reply to Gaelan Steele • • •right, so a Monad is a typeclass (what in most languages you’d call an interface), which represents some sort of “wrapper” around another type. it has an operation, called >>= or “bind”, which takes a Monad<T> and a function(T -> Monad<U>), and returns a Monad<U>. (there’s also “pure”, which just takes a T and returns a Monad<T>)
(I’m playing fast and loose with notation here - by Monad<T> I really mean Foo<T>, where Foo implements Monad. different kinds of Monad aren’t generally interchangeable)
examples of monad-shaped things you’re probably familiar with include:
- Promises from JavaScript etc. The bind operator is .then() - it takes a promise, and a function that turns its result into another promise, and gives you a promise for the second result
- Maybe/Option from Rust etc. The bind operator is what Rust calls .and_then() - it takes an Option, and (if it has a value in it) runs your function to get a new value, and returns an Option that’s None if either the original Option was None or your function returned None
in other words, it’s an abstraction for chaining a bunch of steps, each of which have some sort of side effect like “block on IO” or “maybe return null and render the remaining steps pointless”.
Idris’s IO is a monad, and indeed conceptually not far from a JavaScript promise (though, unlike a Promise, creating an IO and discarding it doesn’t immediately go do the thing)
do notation is syntactic sugar for a chain of bind calls, a bit like how JavaScript's async/await is syntactic sugar for a chain of .then() calls. "<-" is the equivalent of await. do notation works for any kind of monad.
annnnnyway, the problem is that List is also a monad (the semantics are besides the point, but roughly the idea is that you can have a series of operations on each item of the list, each of which might produce zero or more list items for the next step to process). so the compiler isn’t sure if your do block is trying to use IO or List as its monad of choice
hopefully that made a nonzero amount of sense!
_Έλλεν Εμίλια Ά. Arson Τζαϊλου
in reply to mcc • • •_Έλλεν Εμίλια Ά. Arson Τζαϊλου
in reply to _Έλλεν Εμίλια Ά. Arson Τζαϊλου • • •Andre Videla
in reply to mcc • • •btw if you have a repl handy, the
:doccommand might help you out. Something like:doc showor:doc Show. You can also see all the signatures of a module by using:browselike:browse Prelude.You can also dynamically load module in the REPL (although that won't load them in the file) and inspect what they export:
or import the module in your file
And then reload and browse the module
Small tidbits that should be advertised earlier in the tutorials
rntz
in reply to mcc • • •idris2docs.sinyax.net/ has docs searchable by function name, it seems.
you can import & get some docs at repl:
Main> :?
... lists all colon-commands
Main> :import System
Imported module System
Main> :doc readFile
... docs for readFile
Main> :browse System
... list of things defined in System
Main> :search Int -> Int
... searches by type, NOT by name.
warning: it appears to assume your terminal is light-on-dark? at least for me it generates some white text on my default-white background.
Idris2 Docs
idris2docs.sinyax.netmcc
in reply to rntz • • •dominic
in reply to mcc • • •technomancy
in reply to mcc • • •yes but with caveats; when people read "spend all day in the repl" it's often read as "spend all day looking at the repl prompt" but the real meaning is more like "your editor is constantly connected to the repl and usually sending entire files over to it"
(you don't actually spend that much time looking at the repl itself)
fabiosantoscode
in reply to technomancy • • •technomancy
in reply to fabiosantoscode • • •just constantly recompiling and running tests as part of the normal feedback loop; editor integration functions allow you to run the currently focused test and see if it passed
you switch to the repl buffer in cases where you specifically need to see the values, yeah
fabiosantoscode
in reply to technomancy • • •@technomancy Very interesting. Thanks for sharing!
When developing I always have a tmux split showing me a test suite that runs when files change, and where I change test filters as I work on different bits. It kind of fulfills this but it's not quite the same.
infra
in reply to mcc • • •Zoe : Void -> a
in reply to mcc • • •mcc reshared this.
Zoe : Void -> a
in reply to Zoe : Void -> a • • •Conor Titania Mc Bride (@pigworker@types.pl)
Conor Titania Mc Bride (types.pl)d@nny disc@
in reply to Zoe : Void -> a • • •Alaric Snell-Pym
in reply to mcc • • •mcc
in reply to Alaric Snell-Pym • • •Alaric Snell-Pym
in reply to mcc • • •Alaric Snell-Pym
in reply to Alaric Snell-Pym • • •Conor Titania Mc Bride
in reply to Alaric Snell-Pym • • •@kitten_tech One thing about my current lecture series is that it's for first years who have just started uni. So although the material is bursting with categorical structure, I am ruthlessly suppressing categorical language.
Category theorist interlopers are given a bingo card full of words. They get to cross off those words one by one, as I very carefully avoid saying them.
@mcc @edwinb
Taneb
in reply to Conor Titania Mc Bride • • •Amélia Liao 🍊😈
in reply to Taneb • • •Cass Alexandru (@NWPT,SPLS)
in reply to Taneb • • •I love the subtlety of this joke 😆
@kitten_tech @mcc @edwinb @pigworker
Conor Titania Mc Bride
in reply to Taneb • • •Alaric Snell-Pym
in reply to Conor Titania Mc Bride • • •bruno
in reply to mcc • • •Ela
in reply to mcc • • •whut
in reply to mcc • • •mcc
in reply to whut • • •Na
in reply to mcc • • •Compiling to Executables — Idris 2.0 Documentation
idris2.readthedocs.ioNa
in reply to Na • • •Compiling to Executables — Idris 2.0 Documentation
idris2.readthedocs.ioHarley Eades
in reply to mcc • • •💙🩷💜 Brett [backup account]
in reply to mcc • • •mcc
in reply to 💙🩷💜 Brett [backup account] • • •💙🩷💜 Brett [backup account]
in reply to mcc • • •Sola
in reply to mcc • • •njplschy
in reply to mcc • • •idris2-pack/INSTALL.md at main · stefan-hoeck/idris2-pack
GitHubmcc
in reply to njplschy • • •mirek kratochvil
in reply to mcc • • •this looks like idris package is declaring incompatibility with newer versions of cabal (which you seem to have installed), might be useful to ping them to bump their versions
(this is annoyingly common with "latest" haskell tooling versions)
mcc
in reply to mirek kratochvil • • •Teemu Kalvas
in reply to mcc • • •mcc
in reply to Teemu Kalvas • • •@tkalvas I'd definitely like to understand applicatives and I'd definitely like to understand Effects.
If I am already doing a survey of functional languages, which language would you recommend looking at if I want to experience effects done right?
Teemu Kalvas
in reply to mcc • • •mcc
in reply to Teemu Kalvas • • •Teemu Kalvas
in reply to mcc • • •Teemu Kalvas
in reply to Teemu Kalvas • • •Vélimir
in reply to mcc • • •mcc
in reply to Vélimir • • •@vchakhno I dunno, vibes just felt funny. Chunky, awkward syntax and the code and documentation all uses a b c d as variable names. Also to be clear the reason I did not like it between the years 2001 and 2025 was i couldn't frickin figure it out.
I posted my diary of learning Haskell last year here: mastodon.social/@mcc/114433465…
RE: mastodon.social/users/mcc/stat…
mcc (@mcc@mastodon.social)
mcc (Mastodon)Vélimir
in reply to mcc • • •I can't really speak for the syntax, seems at its core like lambda calculus + pattern matching + let and where + do notation. I'm familiar with those so that's OK. Not sure how close it maps to ML. Not a fan of the slight differences between case and pattern matching. Multiline sometimes doesn't do what I would like.
I wish there was a dup operator (W combinator), basicly (\f x -> f x x). Somehow every other combinator of BCKW has their own.
I like how operators have slight variations for ease of use. <=<, <$, <*, *> ...
If you're not familiar with using Functors and Applicatives I suggest taking a look at "Learn you a Haskell for great good" which is a free website that's usually recommended to learn Haskell. That's the one I recently learned from, and enjoyed the whole way. It explains them with tons of examples, it makes them really intuitive.
But maybe you've been through this already
I feel like the single letter variable names have their meaning either in their type, or in the algebraic structure they're part of. If you don't know the structure already you're fucked, good luck going from the laws to the use cases...
Personally I've been looking specifically for books and blog posts about common patterns in haskell in order to learn about those structures.
One such example are optics, I haven't seen them yet but they're on my list, and I have a rough idea what Lens/Prisms are for thanks to previous exposure.
Uh. Sorry for the text dump. I'm low on sleep. I hope it's informative somehow.
mcc
Unknown parent • • •mcc
Unknown parent • • •dyssociative function
in reply to mcc • • •mcc
Unknown parent • • •@dysfun @lritter Thank you very much. And I can handle unfriendly but I will poke you first 😀 do you mind if I ask what time zone you are on so I don't wind up dropping a long question at 3 AM your time or something?
Also lritter now that I've started this project again I do hope to get to Scopes.
mcc
Unknown parent • • •@dysfun so here is a question
mcc
2026-10-14 19:48:47
mcc
Unknown parent • • •mcc
Unknown parent • • •I think in principle this helps, one problem is the words "Monad", "Applicative" and "Functor" are in this screenshot black boxes. or are these *definitions*? Does => mean "I am defining the Monad/Applicative/Functor typeclass to be a thing that can do this?"
mcc reshared this.
prozacchiwawa
in reply to mcc • • •@dysfun
Fat arrow => is a typeclass constraint.
(Monad m) => means that the following requires a visible Monad class for m.
cassie
in reply to mcc • • •mcc
Unknown parent • • •mcc
in reply to mcc • • •raphael-proust
in reply to mcc • • •@dysfun shameless self-plug for the tutorial i wrote specifically for the case where you are using monad but don't have all the theoretical background that you think you need
raphael-proust.github.io/code/…
(text in english, code in ocaml)
some people told me it was useful so maybe also useful to you. if not then i'm sorry for the noise.
Dromedary and a half - A no-maths guide to monads
raphael-proust.github.iomcc
in reply to mcc • • •mcc
Unknown parent • • •dyssociative function
Unknown parent • • •mcc
Unknown parent • • •dyssociative function
Unknown parent • • •dyssociative function
Unknown parent • • •so the first thing that might be helpful here is if you monomorphise it a bit. e.g. instead of
m, substituteList.List a -> (a -> List b) -> List b.or you can play a similar game with
IO. in that case,>>=can be thought of as "then". this is why they call monads "programmable semicolons".prozacchiwawa
in reply to mcc • • •@dysfun
for running outside the idris environment, the model is that idris2 --build builds what's in your .ipkg file (example here github.com/prozacchiwawa/idris… ). it drops the finished exe in ./build/exec.
the main module of your program needs a "main : IO ()". unlike ocaml you can't do side effects at the top level.
idris-node-experiments/idris-node-example/idris-node-example.ipkg at main · prozacchiwawa/idris-node-experiments
GitHubmcc
Unknown parent • • •@dysfun @Andrev It also takes 1 minute and 53 seconds on an incremental build if I change the string "Help" to "Helx".
The way I installed idris2 was I installed Racket via apt, and then I ran a bashfile curled from the "pack" website. On the first step, it asked me my scheme interpreter, [racket] was the default [possibly because chez was not installed]. It was *very* slow.
How do I switch from "racket" to "chez"? Do I rerun the bash? Do I have to uninstall the old version first?
mcc reshared this.
dyssociative function
in reply to cassie • • •Jonathan Lamothe
in reply to mcc • •@mcc @gaytabase The type signature syntax is a little weird until you understand it.
So take the example of
(<$>), which as you've seen has a type signature ofFunctor f => (a -> b) -> f a -> f bWhat the
Functor f =>is saying is that for the remainder of the type signature,frepresents any kind of value that is an instance of theFunctortypeclass, but every instance offhas to be the same kind ofFunctor.In other words,
IOis aFunctorand aMaybeis aFunctor, so(a -> b) -> IO a -> IO bwould be valid;(a -> b) -> Maybe a -> Maybe bwould be valid, but(a -> b) -> IO a -> Maybe bwould not be valid, becauseIOandMaybeare different kinds ofFunctors.Maybe that helps?
like this
mcc and prozacchiwawa like this.
mcc
Unknown parent • • •@Andrev @dysfun imagine i deleted ~/.local/state/pack, re-ran the bash script that installs pack, and selected chezscheme this time. then i delete my ./build and re-run idris2 -o. And I get this message.
What do you make of this?
Andre Videla
in reply to mcc • • •@dysfun pack is the way to go, you have a pack config file in your .config. it has a scheme field on which you can put the executable name for your version of scheme (assuming its installed). For me it’s “scheme” on the mac and “chezscheme” on linux, might be different for you. There should be nothing else to change, pack will use the right version of scheme onwards
edit: added screenshot of my config
mcc
Unknown parent • • •@Andrev @dysfun
1. Typing out the command does not change the outcome.
2. time pack exec src/puzzle.idr does work. However it takes 1 minute 51 seconds. so i have not solved the problem from the racket version. a 2 minute iteration time is survivable but pretty painful.
Additionally, although the bash script was told to use chezscheme, when I run "top" while pack is running, I see "racket" is using 100% CPU.
Note that i do not have an ipkg file anywhere.
Andre Videla
in reply to mcc • • •@dysfun
this is the error that idris throws when the path given cannot be found. It looks like the argument parser injested the string ending in "#!/bin/sh" which is clearly clearly wrong on multiple aspects.
2 questions:
pack exec src/puzzle.idr?!?mcc
Unknown parent • • •@Andrev @dysfun Looking in ~/.local/bin, I see an "idris2" and a "pack".
The bash installer for pack said only to delete ~/.local/pack . What is the correct uninstallation procedure for idris/pack? Is it documented somewhere?
Andre Videla
in reply to Andre Videla • • •@dysfun Here is another potential source of confusion. your version of idris installed by pack might not be the same as the one installed by the system. here is an example where the version in bin/idris2 is not the same as the version invoked by pack.
So if you killed pack and reinstalled it, you might not necessarily have killed the old version of idris
EDIT: This is one of the reasons doing anything via pack is a lot more reliable because it will pick the correct version of idris for you current project and keep that up to date, including libraries and tools like idris2-lsp
Andre Videla
Unknown parent • • •cassie
Unknown parent • • •Expanding out:
`(<$>) : Functor f => (a -> b) -> f a -> f b`
you get a form with the implicit arguments written:
`(<$>) : {a, b : Type} -> {f : Type -> Type} -> {auto _ : Functor f} -> (a -> b) -> f a -> f b`
mcc
Unknown parent • • •@dysfun @Andrev scheme="racket"
and "codegen" is not set.
It is increasingly looking like installing idris2 once with racket as your scheme "mines" your system in such a way it is no longer possible to cleanly install a chezscheme version of idris2.
mcc
Unknown parent • • •@dysfun @Andrev this is the messaging i got files.mastodon.social/media_at…
mcc
Unknown parent • • •mcc
Unknown parent • • •@Andrev @dysfun apt-cache search idris doesn't turn anything up. I'm using Debian Trixie. Everyone said pack was pretty good so I'd be happy to use pack if it can work.
In my opinion, it should be possible to move from a racket install to a chez install without the assistance of idris2 staff. IMO the bash script, when it fails noting a duplicate install, should recommend pack uninstall instead of removing one folder, and pack uninstall should kill (or offer to kill) the config file.
mcc
in reply to mcc • • •Andre Videla
in reply to mcc • • •@dysfun couple things:
pack uninstalldoes and doesn't do github.com/stefan-hoeck/idris2… notably it won't change the existing config fileGitHub - stefan-hoeck/idris2-pack
GitHubmcc
Unknown parent • • •dyssociative function
Unknown parent • • •cassie
in reply to dyssociative function • • •@dysfun the Idris 2 docs I am reading explicitly refer to it as a constraint.
idris2.readthedocs.io/en/lates…
It doesn’t have a separate kind like constraints in Haskell but it still seems to make sense to call it a constraint.
Interfaces — Idris 2.0 Documentation
idris2.readthedocs.ioSamael
in reply to mcc • • •@dysfun @Andrev
I have had no luck getting idris2 built and running. There are chez-related test errors in channels (and this is pulling both chez-scheme and idris2 from latest git sources), and it appears to have been this way for some time (unclear how long, and I do not currently have the spoons to dig). I did not try a Racket-based situation, so I may attempt that later.
dyssociative function
in reply to Samael • • •mcc
Unknown parent • • •mcc
Unknown parent • • •Andre Videla
in reply to mcc • • •mcc
Unknown parent • • •dyssociative function
in reply to Andre Videla • • •mcc
in reply to mcc • • •@Andrev @dysfun I filed this bug on Idris:
github.com/idris-lang/Idris2/i…
And a second bug on Pack:
github.com/stefan-hoeck/idris2…
Installing with racket, then reinstalling with chez, results in broken system still using racket · Issue #409 · stefan-hoeck/idris2-pack
mcclure (GitHub)mcc
Unknown parent • • •dyssociative function
in reply to cassie • • •Functor f. all of the undeclared arguments will be ordinary non-auto implicits.mcc
Unknown parent • • •Andre Videla
in reply to mcc • • •pack --bootstrap updatecan fix a lot of things.MHC Levin
Unknown parent • • •@dysfun @Andrev
to
chezor to the name of the chez binary?dyssociative function
in reply to cassie • • •dyssociative function
in reply to dyssociative function • • •Samael
in reply to dyssociative function • • •@dysfun @Andrev
Arch derivative, unfortunately. I haven't been able to push myself back to Gentoo.
idris2-git, chez-scheme-git, idris2-pack-git (all AUR because apparently nobody at arch packages it), though pack never happened because idris2 never succeeded in tests, and pack depends on it. I would attempt to debug, but I'm sick today and don't have the energy.
There's an issue somewhere in one of idris2 or chez-scheme which describes test failures in a container, and that issue perfectly describes the symptoms I see.
dyssociative function
in reply to Samael • • •mcc
Unknown parent • • •@Andrev @mhcat @dysfun ok so on that note
$ pack exec src/puzzle.idr abcd
abcd
# At this moment I edit puzzle.idr so it no longer compiles
$ pack exec src/puzzle.idr abcd
[ fatal ] Error when executing system command.
Command: "/home/mcc/.local/state/pack/install/b6cbc25d5cd2ef2a250556266fd7b68dfc360f8b/idris2/bin/idris2" "--cg" "chez" "--source-dir" "src" "--cg" "chez" "-o" "_tmppack" "src/puzzle.idr"
Error code: 1
# Is this error messaging surprising?
Andre Videla
in reply to MHC Levin • • •@mhcat @dysfun Just to be clear, there are two options here:
mcc
Unknown parent • • •dyssociative function
Unknown parent • • •(this is not entirely true, there is also
let(without theinsuffix you'd normally use forlet)).and the way i would normally write this btw is:
dyssociative function
Unknown parent • • •>>=and>>, i.e. cps. it's syntax sugar over exactly these two operations.mcc
Unknown parent • • •Andre Videla
in reply to mcc • • •GitHub - idris-community/idris2-tutorial: A comprehensive tutorial for the Idris2 programming language
GitHubAndre Videla
in reply to dyssociative function • • •mcc
Unknown parent • • •@dysfun that's not the part that scared me actually. what scared me is the implications concerning the import statement. Say I change "System.File.ReadWrite" into "Console.App.FileIO". I get error "Undefined name 'Control.App.App'"
I add "import Console.App". I get A DIFFERENT ERROR
What happened there??
Am I importing… typeclasses?? Is this like when having a trait in scope in Rust changes which kinds of inferences are possible?!
mcc reshared this.
cassie
in reply to dyssociative function • • •Andre Videla
in reply to Andre Videla • • •@dysfun By the way, since you mentionned you don't have an ipkg file: You will need one to use lsp, you can try:
idris2 --initand set the source directory insrcand place your.idrfiles therepack new bin helloWorldand that will setup a whole project for you including pack.toml, helloWorld.ipkg and test foldersmcc
Unknown parent • • •@dysfun Oh.
Is it weird then that the hint says "Show FileError" not "show FileError"?
mcc
Unknown parent • • •dyssociative function
Unknown parent • • •_Έλλεν Εμίλια Ά. Arson Τζαϊλου
Unknown parent • • •System.File.Error
idris-lang.orgJonathan Lamothe
in reply to mcc • •@mcc @gaytabase If it hasn't been explained elsewhere, the hint is telling you that the
FileErrortype is an instance of theShowtypeclass (which defines theshowfunction). It basically says "I want to be able to represent values of this type as aString."The naming convention is not particularly intuitive, but it's pretty much so baked into Haskell at this point that changing it now would break just about everything. Still, it's not as bad as Lisp's
carandcdr. 🙃Andre Videla
in reply to Andre Videla • • •rlwrap. it's unusable without it. There is an option in pack.toml to make that the defaultdyssociative function
in reply to Andre Videla • • •@Andrev the only thing i remember was some comment a couple of years back (i think it was edwin?) saying he had to change the gc options to make performance better?
but like 2 minutes to compile hello world is clearly beyond the pale. even idris1 didn't take that long!
dyssociative function
in reply to cassie • • •@porglezomp auto can mean two things:
Andre Videla
in reply to Andre Videla • • •The name of the binary is
idris2-lsp, that's the main piece of info your editor needs to have LSP work. The compiler will run on saveAndre Videla
Unknown parent • • •hintis the name the compiler gives to interface instances that are in scope.Stefano Volpe
Unknown parent • • •yeah, type-driven development and hole programming benefit a lot from editor integration, and they're completely orthogonal to how you choose to run your program or whether it's a CLI tool.
@dysfun@treehouse.systems I don't remember the plugin to be terrible though, so I am not sure whether I was using the REPL or not. I was at the very least using
idris2-vimand the Idris2 LSP together for sure.rntz
Unknown parent • • •mcc
Unknown parent • • •mcc
Unknown parent • • •cassie
in reply to mcc • • •Andre Videla
in reply to dyssociative function • • •@dysfun
Here is what I know of what’s going on for chez cheme, and how that relates to other codegens:
once we emit scheme code we call racket or chezscheme and have them compile and optimise the executable, this can take a while especially when linking large projects.
For a hello world this should be fast, no idea why racket is so slow. Chezscheme performs as expected (0.36s) where 0.3 is taken by booting up the runtime, and 0.06 by compiling the executable
mcc
Unknown parent • • •rntz
Unknown parent • • •@dysfun @ionchy concretely,
Main> traverse (\x => if x > 5 then Left "too big" else Right x) [1,2,3,4,5]
Right [1, 2, 3, 4, 5]
Main> traverse (\x => if x > 5 then Left "too big" else Right x) [1,2,3,4,5,6]
Left "too big"
so (traverse f list) is basically list.map(f).collect::<Result<_>>() in Rust.
dyssociative function
in reply to Andre Videla • • •Andre Videla
Unknown parent • • •@dysfun right and if you use
:docyou can also see thatFileErrorhas aShow, it's the last line in the screenshot.You can do this for any type, if you use
:docit will also tell you what interfaces are in scope for that type, the main ones beingEq,Show,Ord, etcmcc
Unknown parent • • •@dysfun
1. I see that. However, semantics are not the only important thing to me. Ergonomics are very important. As you can see from my conversation with porglezomp, not knowing which of Left and Right is "Error" vs "Ok" is messing with me bad.
2. I'm not using map anymore. I'm using "traverse", and I'm using Data.Either "mirror" to switch lefts and rights. Traverse doesn't switch anything either; however, it chose different semantics for Left and Right than I was using (hence me using mirror)
mcc
in reply to mcc • • •@dysfun 3. I'm getting an error when I try to traverse over a List1. Is the error appearing in the "wrong place", and in fact what's happening is the type unifier is angry I'm returning a List1 from a function that's typed as returning List?
Actually this is a problem. I *want* to return List. Zero values is an option. I guess I need to somehow convert the List1 to List
_Έλλεν Εμίλια Ά. Arson Τζαϊλου
in reply to mcc • • •mcc
in reply to _Έλλεν Εμίλια Ά. Arson Τζαϊλου • • •_Έλλεν Εμίλια Ά. Arson Τζαϊλου
in reply to mcc • • •mcc
in reply to _Έλλεν Εμίλια Ά. Arson Τζαϊλου • • •mcc
Unknown parent • • •dyssociative function
in reply to rntz • • •mcc
Unknown parent • • •dyssociative function
Unknown parent • • •Prelude.Types
idris-lang.orgAmélia Liao 🍊😈
Unknown parent • • •bimap f id"-style omissionmcc
in reply to mcc • • •@dysfun @amy Boo, I guess not.
(I had a tuple of Eithers with heterogenous Rights but all Lefts were String, I was trying to turn them into Either String (<Tuple>) with the leftmost String
mcc
Unknown parent • • •mcc
Unknown parent • • •Andre Videla
Unknown parent • • •Data.Vectand useVect 4 Intinstead of tuples. That will have the expected APIdyssociative function
Unknown parent • • •<-or you can just use standard do syntax and the first left will be returned, that works so long as all the lefts are the same type.Andre Videla
in reply to mcc • • •@dysfun @ionchy
I feel like you might invite a number of l33t h4ck3r solutions that aren't necessarily succesful in explaining themselves. It might be worth going through reinventing the wheel first before jumping to the magical incantation of higher order functions that make this work.
From this I get the feeling that you want to write a function
and stop or "crash" when something doesn't parse, here is something you can do:
This is the bog standard recursive function that traverses a list, nothing fancy here, no higher order function, no magic
traverseorApplicative.And then when you're parsing the element in main you can kill the program post-hoc
This is the first most simple most declarative way to write this program that one should write before trying to interleave monadic control flow with applicatives etc.
mcc
in reply to mcc • • •aoc2024/17-01-cpu/src/puzzle.idr at d15c57397feea3bcdec11182c61dd00610181bc4 · mcclure/aoc2024
GitHubmcc
Unknown parent • • •@dysfun Okay so I would expect
(forget |> split (== ',') tape)
To transform into
(forget (split (== ',') tape)
but when i actually substitute the second for the first I get a very complicated type error. Am I missing something?
mcc
Unknown parent • • •samir, slightly sozzled
in reply to mcc • • •<|.dyssociative function
in reply to Andre Videla • • •@Andrev yes, sorry, what i mean is selecting the racket codegen is still running it under chez, no? just like i can select the javascript codegen and it's still running under chez? i guess it has to call racket afterwards?
but that's clearly a lot slower. and apparently on the scale of compiling hello world entirely on racket, that's 2 minutes.
dyssociative function
in reply to dyssociative function • • •njplschy
Unknown parent • • •=>in Idris and->in Haskellmcc
Unknown parent • • •cassie
Unknown parent • • •Amélia Liao 🍊😈
in reply to mcc • • •split ...has typeList1 String, sotraverse ... (split ...)has typeEither String (List1 Int), somirror (traverse ...)has typeEither (List1 Int) String, notEither (List Int) String.mcc
Unknown parent • • •mcc
Unknown parent • • •@dysfun I picked Nat because I didn't want a fixed size.
Also wait a minute does this. Does this language have or not have a Uint64 type? Or am I supposed to use Bits64 even for doing regular math? 🙁
mcc
Unknown parent • • •mcc
Unknown parent • • •mcc
Unknown parent • • •@dysfun Looks like that's a no.
Error: While processing right hand side of main. While processing right hand side
of main,step. Can't find an implementation for Cast Bits64 (Type -> Nat).
src.puzzle:118:16--118:27
114 | _ =>
115 | die "Unexpected opcode"
116 |
117 | step (NewCpu ip reg prog) =
118 | let ip_idx = cast ip Nat in
^^^^^^^^^^^
Warning: compiling hole Main.main
mcc
Unknown parent • • •dyssociative function
Unknown parent • • •mcc
Unknown parent • • •@dysfun i don't understand what you're asking. bit math is a form of math. sometimes one performs math on indexes. there are a variety of potential reasons.
i agree that i would fix this with multiple interfaces (Bits and BoundedBits)
mcc
Unknown parent • • •Andre Videla
in reply to Andre Videla • • •@dysfun @ionchy
Then you can start to progressively add higher order functions. for example, you mentionned
mapand here is how you can write the sameparsefunction withmap:This works because
catMaybes : List (Maybe a) -> List awill do the work of skipping elements that areNothing.mcc
Unknown parent • • •mcc
Unknown parent • • •"let x in…" it allows me to indent afterward and sometimes not.
mcc
Unknown parent • • •Andre Videla
in reply to mcc • • •@dysfun by the way,
Natis not obviously a subset of Bits64 in Idris:Nat is an inductive datatype, it's semantically a linked list of empty nodes. And it represents unary numbers starting from zero. Nat is defined as
If we didn't aggresively optimise away this representation, each nat would be a heap-allocated list of pointers. This may sound scary but it's in fact the right tool for the job, and it's compiled to BigInt.
Bits64is an opaque type with backend-specifc semantics. For example the way they perform between therefcbackend,nodeandchezis completely different. Typically,Natis faster onchezthanBits64.mcc
in reply to mcc • • •@dysfun also, staying at the same line doesn't seem to help (and it doesn't work if I indent the "if", either)
Andre Videla
in reply to mcc • • •record(and the opcodes asdata) and the interpreter as modifying the record. This way you can split the execution of the CPU and the parsing of the instructions.mcc
Unknown parent • • •mcc
Unknown parent • • •dyssociative function
Unknown parent • • •Structuring Idris 2 Applications — Idris 2.0 Documentation
idris2.readthedocs.iomcc
Unknown parent • • •@dysfun Okay now I'm REALLY confused what the rules are. Second is same but i removed one indent (due to in other cirucmstances being told i'm not allowed to indent)
mcc
Unknown parent • • •Andre Videla
in reply to mcc • • •@dysfun When the code is compiled they should both be represented as a vector of 64 bits. The difference lies in the semantics of the code as it is being compiled and analysed.
When we are looking at
Natthe compiler sees it as a unary algebraic data type. That's necessary to achieve features like termination checking (totality), compile-time evaluation of types likeVect (3 + 4), and propagation of invariants likeFin n -> Fin (S n). All this compile-time analysis can only be done for algebraic data types. But becauseBit64,Int32, etc are not algebraic data types, they are FFI-types we can't compute with them like we can forNat. They are totally opaque from the perspective of the typechecker.If we could somehow turn
Bits64into an algebraic data type, then we could more closely match it toNat. And in fact we can!Bit64is equivalent to the algebraic data typeVect 64 Bool.And now you can see that the semantics of
Vect 64 Boolare not the same at all asNat. the first one is a list of fixed length of booleans and the other is a possibly infinite list of empty nodes, there is no type theory in which those types are subtypes of each other.mcc
Unknown parent • • •mcc
Unknown parent • • •mcc
Unknown parent • • •@Andrev @dysfun It seems to me Integer can have bit-level operations as long as your bignum implementation can represent the number …11110 consisting of a 0 to the left of the decimal point followed by an infinite number of 1s to the left of that.
Can it?
Andre Videla
in reply to mcc • • •@dysfun Some of this is historical baggage and mistakes that were never fixed.
I think there is a pretty good consensus that
Intshould be removed, andIntegershouldn't have bit-level operations.mcc
Unknown parent • • •mcc
Unknown parent • • •Andre Videla
in reply to mcc • • •castis a little bit misleading if you expect some sort of type coercion to happen.castis a function from theCastinterface that is "known to be lossy". You can implementcastbetween any to types and do any sorts of shenanigans likeThe typechecker has no knowledge of the final bit representation of the data and that does not inform what can or cannot be
castmcc
Unknown parent • • •@dysfun
mcc
Unknown parent • • •@dysfun I think what is actually happening is that the else statement is a "die" which is monadic and I can't put it there.
mcc
Unknown parent • • •dyssociative function
Unknown parent • • •mag
in reply to mcc • • •dyssociative function
in reply to cassie • • •Amélia Liao 🍊😈
in reply to Amélia Liao 🍊😈 • • •split (== ',') tape? split takes two arguments, you've given it one.mcc
Unknown parent • • •mcc
Unknown parent • • •Andre Videla
in reply to mcc • • •@dysfun I wrote a big draft and lost it and now I'm not even sure how to answer this. as a summary
dyssociative function
Unknown parent • • •mcc
Unknown parent • • •dyssociative function
Unknown parent • • •mcc
in reply to Andre Videla • • •@Andrev @dysfun Hey so
I would like to file an issue on Idris2
complaining that :doc for the following items
Data.Fin.natToFin
div
mod
do not have text descriptions
natToFin is a real problem because the argument order is NOT obvious
div i think is integer divide drop remainder but i'm not sure
mod is a real problem because you need to explain behavior with negatives
is the github main Idris2 the place to file issues concerning stdlib/docs
mcc
in reply to mcc • • •The Idris 2 Programming Langauge - Idris 2 Tutorial
idris-community.github.ioAndre Videla
in reply to Andre Videla • • •@dysfun @ionchy
Of course your original intent was to write an imperative program with control flow and in the previous example we're delaying the control flow operation to later, and that's less efficient. What we want is a function that will first tell you to break control flow as you are going through the list. Someone mentionned
Eitherbefore but we can also useMaybeand for that we should go back to our bog standard recursive implementation:The first change is to return
Maybe (List Int)to indicate that if we need to abort the program, the parse function returnsNothing:After that we modify our implementation , I'm going to put holes for the compilcated parts
If you ask the repl
:t h1it will tell you:At this point of the program we need to return either a list, or a
Nothing. because this is the branch where parsing failed, we are going to returnNothingindicating that we return immediately and abandon building a list of integers.if you ask
:t h2, you see that we have an integer withi:But we also need to compute the rest of the list, we only have the head element. And this head element is useless if there is a parse error later. So we compute the rest of the arguments first:
Now
rest : Maybe (List Int)is the rest of the strings parser as integers, if there was an error in the rest, this would beNothing. If everything parsed correctly, this would beJust, we do case-analysis to explore those two branches:now
h1 : Maybe (List Int)and it's in the branch where something went wrong with the rest of the list. in this case, we can drop theiand return immediately withNothingFor
h1 : Maybe (List Int)we know thatiis the correctly parsed "current" element andisis the rest of the correctly parsed future elements. This means everything has gone well and we can return a value withJustandconsour element and the rest of the elements together:which leads to the following function:
Again, no higher order function, no l33t h4ck3r magic, just functions, pattern-matching and recursion.
Now you can call
parseand if you getNothingyou can kill the program, and if you getJustyou can proceedSorry this was a bit long
Andre Videla
in reply to mcc • • •Andre Videla
in reply to Andre Videla • • •it's bed time for me but it occurs to me that I wrote a lot of similar code for AOC 2020 if you want some inspiration or are just curious. There are accompanying reports along with the code, for example day 8 had a basic cpu:
Day8.md · master · André Videla / AOC2020 · GitLab
GitLabHeribert Schütz
Unknown parent • • •Sensitive content
And here is a somewhat simplified version (in JS syntax):
let out = [], A = 41644071;
// 41644071 is from part 1. Find an appropriate value in part 2.
do {
const B = A & 0b111;
out.push((B ^ 5 ^ (A >> (B ^ 2))) & 0b111);
} while (A >>= 3);
console.log(JSON.stringify(out));
So yes, it decomposes A into chunks of 3 bits (i.e., octal digits), and we probably have to make use of this.
But I don't have an idea yet how to deal with the subexpression (A >> (B ^ 2))
dyssociative function
in reply to Andre Videla • • •mcc
Unknown parent • • •mcc
Unknown parent • • •Amélia Liao 🍊😈
in reply to Amélia Liao 🍊😈 • • •splitworks because you've only given it one argument. theList Inton the right of the mismatch is coming from the type signature (throughmirror), the function type on the left is becausesplitis underappliedmcc
Unknown parent • • •Andre Videla
in reply to mcc • • •@dysfun just like everything, there is an infinite rabbit hole depending on your affinity:
If you're dead set on high performance bit-level operations I encourage you to look at Data.Buffer. Either your will rejoice or recoil in horror.
There is yet some more type theory involving linear types for fast array manipulation and idris2-array is the state of the art in that regard github.com/stefan-hoeck/idris2…
Finally there is the way functional programmer go about those challenges and that's to parse away from the fiddly bits and into a small and well defined set of types that exactly capture the semantics of the program
GitHub - stefan-hoeck/idris2-array: Immutable and mutable (linear) arrays
GitHubmcc
Unknown parent • • •@dysfun Presumably I imagine I'd write a proof. mastodon.social/@mcc/117497422…
mcc
2026-10-24 18:59:52
mcc
Unknown parent • • •mcc
in reply to mcc • • •mcc
Unknown parent • • •Andre Videla
in reply to mcc • • •Andre Videla
in reply to mcc • • •@dysfun that would be an issue on the tutorial project github.com/idris-community/idr…
You could also open a PR I think people will accept it quite fast
GitHub - idris-community/idris2-tutorial: A comprehensive tutorial for the Idris2 programming language
GitHubmcc
Unknown parent • • •mcc
in reply to mcc • • •mcc
Unknown parent • • •@dysfun oh, no
this is… "list context"? how do i coerce into list context?
in haskell there's this thing called amb but i assume we're not talking about amb
mcc
Unknown parent • • •_Έλλεν Εμίλια Ά. Arson Τζαϊλου
in reply to mcc • • •@dysfun @typeswitch > Geez this is just Perl
yes. that's what makes it good 😉 lmao (at least, that's what I most like about Haskell, Idris and Perl)
Andre Videla
in reply to Andre Videla • • •@dysfun @ionchy
From this you can start adding back higher order functions, for example the case-analysis on
Maybeis in fact themapfunction for maybe:The intermediate variable names aren't necessary, you can inline everything:
the case analysis on
parseIntegerlooks like map but this won't work because the return type is also aMaybe, this is where bind (or>>=) becomes useful:and it turns out that this is exactly what
do-notation is for:I don't expect anyone to follow through all those steps at the begining, but having this sequence of step is handy to help make the connection between higher-order functions and other existing patterns in the language. The more you write repetitive code, the more you might think "huh, is there a function for that?" and seeing some of them here is a good hint for things to look out for.
mcc
Unknown parent • • •mcc
in reply to mcc • • •mcc
Unknown parent • • •@dysfun well, if "trait" means an implicit "…in Rust", i actually do often find Rust's trait magic frustrating and if Rust didn't have such good error messages I'd probably find it intolerable, But also, Rust is different because it has Turbofish.
Can I say something like
do : IO ()
x <- 3
...
And *definitely* the do block believes it's -> IO () and errors if something else is inferred? That's what I'd need to be comfortable with this
mcc
Unknown parent • • •mcc
Unknown parent • • •mei
Unknown parent • • •mcc
Unknown parent • • •mcc
Unknown parent • • •@dysfun @typeswitch oh rly
let next_candidates = map (.|.) candidates <*> digits
Hmm… do I like that better? I think it might be worse actually because I'm unclear what <*> is binding to and the currying feels "magic" in a bad way
mcc
Unknown parent • • •Crazazy @ my computer c:
in reply to mcc • • •Dieu
in reply to mcc • • •crab
in reply to mcc • • •mcc
in reply to crab • • •@operand @dysfun the terms of the challenge is 25 languages i've never written a program in before. and i've written Prolog before.
i think i have a couple logic languages on my candidates list. i'd like to learn kanren someday. i've tried a couple times and always go "ah! that makes sense! … how do i use it?"
crab
in reply to mcc • • •dyssociative function
Unknown parent • • •it's just a function. yes it's generic over the list type.
a =>desugars to{auto _ : a} ->mcc
in reply to dyssociative function • • •KielKontrovers Blog
Unknown parent • • •Ursidinoj/The Bjornsdottirs
Unknown parent • • •LR
Unknown parent • • •mcc
Unknown parent • • •demize
Unknown parent • • •oh apparently they only serve breakfast until 4pm now…
in the late 2010s we started getting all day breakfast everywhere but now it’s hit-or-miss at mcdonald’s and only all morning-and-afternoon at tim’s… is the last bastion of all day breakfast A&W??
typeswitch
Unknown parent • • •@dysfun there's also the secret third notation that i just remembered ... list comprehensions
[ (x,y) | x <- xs, y <- ys ]
this is the same as the above but specifically for lists.
idris2.readthedocs.io/en/lates…
Types and Functions — Idris 2.0 Documentation
idris2.readthedocs.io