Closed YuMingLiao closed 1 year ago
Very strange. I'll try to reproduce this to prevent this sort of crash since this could be used as a denial-of-service attack.
At a higher level, though, the length function should likely be built-in and available by default.
I faced a different issue:
TutorialD (master/main): addatomfunction "textLength" Text -> Either AtomFunctionError Int """(\((TextAtom t):_) -> pure $ IntAtom (T.length t)) :: [Atom] -> Either AtomFunctionError Atom """
ERR: Couldn't match expected type ‘Text’
with actual type ‘Text’
NB: ‘Text’
is defined in ‘Data.Text.Internal’ in package ‘text-1.2.4.1’
‘Text’ is defined in ‘Data.Text.Internal’ in package ‘text-2.0’
which is clearly a Data.Text version mismatch but not a crash. That reminded me to delete my pre-built project-m36 library in the .cabal/store
directory using:
ghc-pkg -f ~/.cabal/store/ghc-8.10.7/package.db unregister project-m36-0.9.4
cabal install lib:project-m36 --lib
That's pretty annoying and easy-to-miss but it should only affect developers, but maybe I should make it harder to load a version-mismatched project-m36 library into the scripting environment. Hmm...
After rebuilding against the correct project-m36 version, it does seem to work as expected:
TutorialD (master/main): addatomfunction "textLength" Text -> Either AtomFunctionError Int """(\((TextAtom t):_) -> pure $ IntAtom (T.length t)) :: [Atom] -> Either AtomFunctionError Atom """
TutorialD (master/main): :showexpr true:{a := textLength("A")}
┌──────┐
│a::Int│
├──────┤
│1 │
└──────┘
I think it's likely that you just need to rebuild the project-m36 library which gets loaded by the scripting environment. I'll use this ticket to make it more difficult to load an incompatible version.
I guess you are right on the spot.
I manually offer the ghc library path I nix-env -iA
with upstream project-m36 to my locally-snack-build tutd.
After I uninstall the local one. It works.
TutorialD (master/main): addatomfunction "textLength" Text -> Either AtomFunctionError Int """(\((TextAtom t):_) -> pure $ IntAtom (Data.Text.length t)) :: [Atom] -> Either AtomFunctionError Atom """
TutorialD (master/main): :showexpr true:{a := textLength("A")}
┌──────┐
│a::Int│
├──────┤
│1 │
└──────┘
Thanks very much!
It also happens in pre-compiled atom functions. I'll guess
HasCallStack
inData.Text.length
's type signature has something to do with this problem.