haskellfunctional-programmingsmlcategory-theorycatamorphism# Having trouble translating code from Haskell to SML

I am trying to translate the following piece of code from SML to haskell but I'm having a bit of trouble.

```
type List_alg x u = (u, x->u->u)
list_cata :: List_alg x u -> [x] -> u list_cata (a,f) = cata where
cata[] =a
cata (x:l) = f x (cata l)
```

Here is what I've tried:

```
type ('a, 'b) List_alg = 'b * ('a -> 'b -> 'b)
fun list_cata (((a, f): List_alg), (l: 'a list)): 'b =
case l of
[] => a
| x::xs => f x (list_cata ((a,f), xs))
```

I get the error `Error: type constructor List_alg given 0 arguments, wants 2`

but I'm not sure what is wrong/how to fix that. Any help would be appreciated!

Solution

`List_alg`

is a type constructor that expects two arguments, but you used it without any arguments on the third line. Try changing it to `('a, 'b) List_alg`

as in

```
fun list_cata (((a, f): ('a, 'b) List_alg), (l: 'a list)): 'b =
```

Notice that your Haskell implementation also passes `x`

and `u`

after `List_alg`

- Comparing lists in Haskell
- Is there a non-identity monad morphism M ~> M that is monadically natural in M?
- Problem with loading module ‘Distribution.Simple’
- Improving efficiency in Stirling numbers calculation
- Does sequencing an infinite list of IO actions by definition result in a never-ending action? Or is there a way to bail out?
- How to call pgQuery from postgresql-query?
- How to avoid whitespace after a tag (link) in Hamlet templates?
- Understanding type-directed resolution in Haskell with existential types
- Why is seq bad?
- Understanding bind function in Haskell
- How to create route that will trigger on any path in Servant?
- How do I use a global state in WAI middleware?
- nixos 23.11 cabal install mysql-simple problem - "Missing (or bad) C libraries"
- Is there a way to kill all forked threads in a GHCi session without restarting it?
- Why can an invalid list expression such as 2:1 be assigned to a variable, but not printed?
- Iterate over a type level list and call a function based on each type in the list
- How does this solution of Project Euler Problem 27 in the Haskell Wiki work?
- Why `Monad` is required to use `pure`?
- Can't do partial function definitions in GHCi
- recommended way to convert Double -> Float in Haskell
- Haskell profiling understanding cost centre summary for anonymous lambda
- Why is Haskell fully declarative?
- GHC Generating Redundant Core Operations
- Question about Event firing in reflex-frp
- Using Haskell's "Maybe", type declarations
- How can I elegantly invert a Map's keys and values?
- Why there is no output for wrapped IO in Haskell?
- What are the definitions of Weather and Memory in xmobar repo?
- Serializing a Data.Text value to a ByteString without unnecessary \NUL bytes
- Using Haskell with VS Code